From a40eb156185ce2c4e6244f8877150cb2b2eaa4c8 Mon Sep 17 00:00:00 2001 From: Carlos Alexandro Becker Date: Sat, 4 Mar 2023 12:16:37 -0300 Subject: [PATCH] feat: add base template function (#3834) refs #3833 Signed-off-by: Carlos A Becker --- internal/tmpl/tmpl.go | 1 + internal/tmpl/tmpl_test.go | 2 ++ www/docs/customization/templates.md | 1 + 3 files changed, 4 insertions(+) diff --git a/internal/tmpl/tmpl.go b/internal/tmpl/tmpl.go index 720f906b4..626de96db 100644 --- a/internal/tmpl/tmpl.go +++ b/internal/tmpl/tmpl.go @@ -214,6 +214,7 @@ func (t *Template) Apply(s string) (string, error) { "trimsuffix": strings.TrimSuffix, "title": cases.Title(language.English).String, "dir": filepath.Dir, + "base": filepath.Base, "abs": filepath.Abs, "incmajor": incMajor, "incminor": incMinor, diff --git a/internal/tmpl/tmpl_test.go b/internal/tmpl/tmpl_test.go index 15538e582..609418d46 100644 --- a/internal/tmpl/tmpl_test.go +++ b/internal/tmpl/tmpl_test.go @@ -73,6 +73,8 @@ func TestWithArtifact(t *testing.T) { "artifact name: not-this-binary": "artifact name: {{ .ArtifactName }}", "artifact ext: .exe": "artifact ext: {{ .ArtifactExt }}", "artifact path: /tmp/foo.exe": "artifact path: {{ .ArtifactPath }}", + "artifact basename: foo.exe": "artifact basename: {{ base .ArtifactPath }}", + "artifact dir: /tmp": "artifact dir: {{ dir .ArtifactPath }}", "remove this": "{{ filter .Env.MULTILINE \".*remove.*\" }}", "something with\nmultiple lines\nto test things": "{{ reverseFilter .Env.MULTILINE \".*remove.*\" }}", diff --git a/www/docs/customization/templates.md b/www/docs/customization/templates.md index 3c6c3b49a..aec622e46 100644 --- a/www/docs/customization/templates.md +++ b/www/docs/customization/templates.md @@ -135,6 +135,7 @@ Usage |Description `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). +`base .Path` |returns the last element of path. See [Base](https://golang.org/pkg/path/filepath/#Base). Since v1.16. `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.