mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-03-17 20:47:50 +02:00
feat: Add trimprefix function to template package (#2116)
This allows templates to trim prefixes. Particularly useful for removing the v prefix from versions
This commit is contained in:
parent
f87eeac346
commit
e0c3abae2e
@ -166,11 +166,12 @@ func (t *Template) Apply(s string) (string, error) {
|
||||
"time": func(s string) string {
|
||||
return time.Now().UTC().Format(s)
|
||||
},
|
||||
"tolower": strings.ToLower,
|
||||
"toupper": strings.ToUpper,
|
||||
"trim": strings.TrimSpace,
|
||||
"dir": filepath.Dir,
|
||||
"abs": filepath.Abs,
|
||||
"tolower": strings.ToLower,
|
||||
"toupper": strings.ToUpper,
|
||||
"trim": strings.TrimSpace,
|
||||
"trimprefix": strings.TrimPrefix,
|
||||
"dir": filepath.Dir,
|
||||
"abs": filepath.Abs,
|
||||
}).
|
||||
Parse(s)
|
||||
if err != nil {
|
||||
|
@ -188,6 +188,11 @@ func TestFuncMap(t *testing.T) {
|
||||
Name: "tolower",
|
||||
Expected: "test",
|
||||
},
|
||||
{
|
||||
Template: `{{ trimprefix "v1.2.4" "v" }}`,
|
||||
Name: "trimprefix",
|
||||
Expected: "1.2.4",
|
||||
},
|
||||
{
|
||||
Template: `{{ toupper "test" }}`,
|
||||
Name: "toupper",
|
||||
|
@ -62,6 +62,7 @@ On all fields, you have these available functions:
|
||||
| `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 [TrimSpace](https://golang.org/pkg/strings/#TrimPrefix) |
|
||||
| `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) |
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user