mirror of
https://github.com/goreleaser/goreleaser.git
synced 2024-12-29 01:44:39 +02:00
feat: title template function (#3590)
added new `title` template function. extracted from #3589 Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>
This commit is contained in:
parent
fb901ae6d3
commit
f3f1c08caf
2
go.mod
2
go.mod
@ -41,6 +41,7 @@ require (
|
||||
golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa
|
||||
golang.org/x/oauth2 v0.0.0-20220722155238-128564f6959c
|
||||
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4
|
||||
golang.org/x/text v0.3.7
|
||||
gopkg.in/mail.v2 v2.3.1
|
||||
gopkg.in/yaml.v3 v3.0.1
|
||||
)
|
||||
@ -154,7 +155,6 @@ require (
|
||||
go.opencensus.io v0.23.0 // indirect
|
||||
golang.org/x/net v0.0.0-20220805013720-a33c5aa5df48 // indirect
|
||||
golang.org/x/sys v0.1.0 // indirect
|
||||
golang.org/x/text v0.3.7 // indirect
|
||||
golang.org/x/time v0.0.0-20220722155302-e5dcc9cfc0b9 // indirect
|
||||
golang.org/x/xerrors v0.0.0-20220609144429-65e65417b02f // indirect
|
||||
google.golang.org/api v0.91.0 // indirect
|
||||
|
@ -14,6 +14,8 @@ import (
|
||||
"github.com/goreleaser/goreleaser/internal/artifact"
|
||||
"github.com/goreleaser/goreleaser/pkg/build"
|
||||
"github.com/goreleaser/goreleaser/pkg/context"
|
||||
"golang.org/x/text/cases"
|
||||
"golang.org/x/text/language"
|
||||
)
|
||||
|
||||
// Template holds data that can be applied to a template string.
|
||||
@ -185,6 +187,7 @@ func (t *Template) Apply(s string) (string, error) {
|
||||
"trim": strings.TrimSpace,
|
||||
"trimprefix": strings.TrimPrefix,
|
||||
"trimsuffix": strings.TrimSuffix,
|
||||
"title": cases.Title(language.English).String,
|
||||
"dir": filepath.Dir,
|
||||
"abs": filepath.Abs,
|
||||
"incmajor": incMajor,
|
||||
|
@ -227,6 +227,11 @@ func TestFuncMap(t *testing.T) {
|
||||
Name: "trimsuffix",
|
||||
Expected: "https://github.com/foo/bar",
|
||||
},
|
||||
{
|
||||
Template: `{{ title "file" }}`,
|
||||
Name: "title",
|
||||
Expected: "File",
|
||||
},
|
||||
{
|
||||
Template: `{{ .ReleaseURL }}`,
|
||||
Name: "trimsuffix",
|
||||
|
@ -104,18 +104,19 @@ On all fields, you have these available functions:
|
||||
|
||||
Usage |Description
|
||||
------------------------------|------------------------------------------------------------------------------------------------------------------------------
|
||||
`replace "v1.2" "v" ""` |replaces all matches. See [ReplaceAll](https://golang.org/pkg/strings/#ReplaceAll)
|
||||
`replace "v1.2" "v" ""` |replaces all matches. See [ReplaceAll](https://golang.org/pkg/strings/#ReplaceAll).
|
||||
`split "1.2" "."` |split string at separator. See [Split](https://golang.org/pkg/strings/#Split). Since v1.11.
|
||||
`time "01/02/2006"` |current UTC time in the specified format (this is not deterministic, a new time for every call)
|
||||
`tolower "V1.2"` |makes input string lowercase. See [ToLower](https://golang.org/pkg/strings/#ToLower)
|
||||
`toupper "v1.2"` |makes input string uppercase. See [ToUpper](https://golang.org/pkg/strings/#ToUpper)
|
||||
`trim " v1.2 "` |removes all leading and trailing white space. See [TrimSpace](https://golang.org/pkg/strings/#TrimSpace)
|
||||
`trimprefix "v1.2" "v"` |removes provided leading prefix string, if present. See [TrimPrefix](https://golang.org/pkg/strings/#TrimPrefix)
|
||||
`trimsuffix "1.2v" "v"` |removes provided trailing suffix string, if present. See [TrimSuffix](https://pkg.go.dev/strings#TrimSuffix)
|
||||
`dir .Path` |returns all but the last element of path, typically the path's directory. See [Dir](https://golang.org/pkg/path/filepath/#Dir)
|
||||
`abs .ArtifactPath` |returns an absolute representation of path. See [Abs](https://golang.org/pkg/path/filepath/#Abs)
|
||||
`time "01/02/2006"` |current UTC time in the specified format (this is not deterministic, a new time for every call).
|
||||
`tolower "V1.2"` |makes input string lowercase. See [ToLower](https://golang.org/pkg/strings/#ToLower).
|
||||
`toupper "v1.2"` |makes input string uppercase. See [ToUpper](https://golang.org/pkg/strings/#ToUpper).
|
||||
`trim " v1.2 "` |removes all leading and trailing white space. See [TrimSpace](https://golang.org/pkg/strings/#TrimSpace).
|
||||
`trimprefix "v1.2" "v"` |removes provided leading prefix string, if present. See [TrimPrefix](https://golang.org/pkg/strings/#TrimPrefix).
|
||||
`trimsuffix "1.2v" "v"` |removes provided trailing suffix string, if present. See [TrimSuffix](https://pkg.go.dev/strings#TrimSuffix).
|
||||
`dir .Path` |returns all but the last element of path, typically the path's directory. See [Dir](https://golang.org/pkg/path/filepath/#Dir).
|
||||
`abs .ArtifactPath` |returns an absolute representation of path. See [Abs](https://golang.org/pkg/path/filepath/#Abs).
|
||||
`filter "text" "regex"` |keeps only the lines matching the given regex, analogous to `grep -E`. Since v1.6.
|
||||
`reverseFilter "text" "regex"`|keeps only the lines **not** matching the given regex, analogous to `grep -vE`. Since v1.6.
|
||||
`title "foo"` |"titlenize" the string using english as language. See [Title](https://pkg.go.dev/golang.org/x/text/cases#Title). Since v1.14.
|
||||
|
||||
With all those fields, you may be able to compose the name of your artifacts
|
||||
pretty much the way you want:
|
||||
|
Loading…
Reference in New Issue
Block a user