1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-11-06 09:09:29 +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:
Kumbirai Tanekha
2021-03-17 17:19:32 +00:00
committed by GitHub
parent f87eeac346
commit e0c3abae2e
3 changed files with 12 additions and 5 deletions

View File

@@ -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 {

View File

@@ -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",