Skip to content

Commit 776e11f

Browse files
committed
feat: aliases to Sprig functions masked by docker-gen functions
1 parent d4857de commit 776e11f

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,14 @@ For example, this is a JSON version of an emitted RuntimeContainer struct:
415415
- _`whereLabelDoesNotExist $containers $label`_: Filters a slice of containers based on the non-existence of the label `$label`.
416416
- _`whereLabelValueMatches $containers $label $pattern`_: Filters a slice of containers based on the existence of the label `$label` with values matching the regular expression `$pattern`.
417417

418+
Sprig functions that have the same name as docker-gen function (but different behaviour) are made available with the `sprig` prefix:
419+
420+
- _`sprigContains $string $string`_: Alias for Sprig's [`contains`](https://masterminds.github.io/sprig/strings.html).
421+
- _`sprigDir $path`_: Alias for Sprig's [`dir`](https://masterminds.github.io/sprig/paths.html).
422+
- _`sprigReplace $old $new $string`_: Alias for Sprig's [`replace`](https://masterminds.github.io/sprig/strings.html).
423+
- _`sprigSplit $sep $string`_: Alias for Sprig's [`split`](https://masterminds.github.io/sprig/string_slice.html).
424+
- _`sprigSplitn $sep $count $string"`_: Alias for Sprig's [`splitn`](https://masterminds.github.io/sprig/string_slice.html).
425+
418426
Some functions are aliases for Go's [`strings`](https://pkg.go.dev/strings) package functions:
419427

420428
- _`parseBool $string`_: Alias for [`strconv.ParseBool`](http://golang.org/pkg/strconv/#ParseBool). Returns the boolean value represented by `$string`. It accepts 1, t, T, TRUE, true, True, 0, f, F, FALSE, false, False. Any other value returns an error.

internal/template/template.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,13 @@ func newTemplate(name string) *template.Template {
106106
"json": sprigFuncMap["mustToJson"],
107107
"parseJson": sprigFuncMap["mustFromJson"],
108108
"sha1": sprigFuncMap["sha1sum"],
109+
110+
// aliases to sprig template functions masked by docker-gen functions with the same name
111+
"sprigContains": sprigFuncMap["contains"],
112+
"sprigDir": sprigFuncMap["dir"],
113+
"sprigReplace": sprigFuncMap["replace"],
114+
"sprigSplit": sprigFuncMap["split"],
115+
"sprigSplitn": sprigFuncMap["splitn"],
109116
})
110117
}
111118

0 commit comments

Comments
 (0)