Skip to content

Commit d4857de

Browse files
committed
docs: update README
1 parent 7b0dc47 commit d4857de

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

README.md

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,6 @@ For example, this is a JSON version of an emitted RuntimeContainer struct:
384384
- [Functions from Go](https://pkg.go.dev/text/template#hdr-Functions)
385385
- [Functions from Sprig v3](https://masterminds.github.io/sprig/), except for those that have the same name as one of the following functions.
386386
- _`closest $array $value`_: Returns the longest matching substring in `$array` that matches `$value`
387-
- _`coalesce ...`_: Returns the first non-nil argument.
388387
- _`comment $delimiter $string`_: Returns `$string` with each line prefixed by `$delimiter` (helpful for debugging combined with Sprig `toPrettyJson`: `{{ toPrettyJson $ | comment "#" }}`).
389388
- _`contains $map $key`_: Returns `true` if `$map` contains `$key`. Takes maps from `string` to any type.
390389
- _`dir $path`_: Returns an array of filenames in the specified `$path`.
@@ -398,23 +397,13 @@ For example, this is a JSON version of an emitted RuntimeContainer struct:
398397
- _`groupByLabelWithDefault $containers $label $defaultValue`_: Returns the same as `groupBy` but grouping by the given label's value. Containers that do not have the `$label` set are included in the map under the `$defaultValue` key.
399398
- _`include $file`_: Returns content of `$file`, and empty string if file reading error.
400399
- _`intersect $slice1 $slice2`_: Returns the strings that exist in both string slices.
401-
- _`json $value`_: Returns the JSON representation of `$value` as a `string`.
402400
- _`fromYaml $string` / `mustFromYaml $string`_: Similar to [Sprig's `fromJson` / `mustFromJson`](https://github.com/Masterminds/sprig/blob/master/docs/defaults.md#fromjson-mustfromjson), but for YAML.
403401
- _`toYaml $dict` / `mustToYaml $dict`_: Similar to [Sprig's `toJson` / `mustToJson`](https://github.com/Masterminds/sprig/blob/master/docs/defaults.md#tojson-musttojson), but for YAML.
404402
- _`keys $map`_: Returns the keys from `$map`. If `$map` is `nil`, a `nil` is returned. If `$map` is not a `map`, an error will be thrown.
405-
- _`parseBool $string`_: parseBool returns the boolean value represented by the string. It accepts 1, t, T, TRUE, true, True, 0, f, F, FALSE, false, False. Any other value returns an error. Alias for [`strconv.ParseBool`](http://golang.org/pkg/strconv/#ParseBool)
406-
- _`replace $string $old $new $count`_: Replaces up to `$count` occurences of `$old` with `$new` in `$string`. Alias for [`strings.Replace`](http://golang.org/pkg/strings/#Replace)
407-
- _`sha1 $string`_: Returns the hexadecimal representation of the SHA1 hash of `$string`.
408-
- _`split $string $sep`_: Splits `$string` into a slice of substrings delimited by `$sep`. Alias for [`strings.Split`](http://golang.org/pkg/strings/#Split)
409-
- _`splitN $string $sep $count`_: Splits `$string` into a slice of substrings delimited by `$sep`, with number of substrings returned determined by `$count`. Alias for [`strings.SplitN`](https://golang.org/pkg/strings/#SplitN)
410403
- _`sortStringsAsc $strings`_: Returns a slice of strings `$strings` sorted in ascending order.
411404
- _`sortStringsDesc $strings`_: Returns a slice of strings `$strings` sorted in descending (reverse) order.
412405
- _`sortObjectsByKeysAsc $objects $fieldPath`_: Returns the array `$objects`, sorted in ascending order based on the values of a field path expression `$fieldPath`.
413406
- _`sortObjectsByKeysDesc $objects $fieldPath`_: Returns the array `$objects`, sorted in descending (reverse) order based on the values of a field path expression `$fieldPath`.
414-
- _`trimPrefix $prefix $string`_: If `$prefix` is a prefix of `$string`, return `$string` with `$prefix` trimmed from the beginning. Otherwise, return `$string` unchanged.
415-
- _`trimSuffix $suffix $string`_: If `$suffix` is a suffix of `$string`, return `$string` with `$suffix` trimmed from the end. Otherwise, return `$string` unchanged.
416-
- _`toLower $string`_: Replace capital letters in `$string` to lowercase.
417-
- _`toUpper $string`_: Replace lowercase letters in `$string` to uppercase.
418407
- _`when $condition $trueValue $falseValue`_: Returns the `$trueValue` when the `$condition` is `true` and the `$falseValue` otherwise
419408
- _`where $items $fieldPath $value`_: Filters an array or slice based on the values of a field path expression `$fieldPath`. A field path expression is a dot-delimited list of map keys or struct member names specifying the path from container to a nested value. Returns an array of items having that value.
420409
- _`whereNot $items $fieldPath $value`_: Filters an array or slice based on the values of a field path expression `$fieldPath`. A field path expression is a dot-delimited list of map keys or struct member names specifying the path from container to a nested value. Returns an array of items **not** having that value.
@@ -426,6 +415,21 @@ For example, this is a JSON version of an emitted RuntimeContainer struct:
426415
- _`whereLabelDoesNotExist $containers $label`_: Filters a slice of containers based on the non-existence of the label `$label`.
427416
- _`whereLabelValueMatches $containers $label $pattern`_: Filters a slice of containers based on the existence of the label `$label` with values matching the regular expression `$pattern`.
428417

418+
Some functions are aliases for Go's [`strings`](https://pkg.go.dev/strings) package functions:
419+
420+
- _`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.
421+
- _`replace $string $old $new $count`_: Alias for [`strings.Replace`](http://golang.org/pkg/strings/#Replace). Replaces up to `$count` occurences of `$old` with `$new` in `$string`.
422+
- _`split $string $sep`_: Alias for [`strings.Split`](http://golang.org/pkg/strings/#Split). Splits `$string` into a slice of substrings delimited by `$sep`.
423+
- _`splitN $string $sep $count`_: Alias for [`strings.SplitN`](https://golang.org/pkg/strings/#SplitN). Splits `$string` into a slice of substrings delimited by `$sep`, with number of substrings returned determined by `$count`.
424+
- _`toLower $string`_: Alias for [`strings.ToLower`](https://pkg.go.dev/strings#ToLower). Replace capital letters in `$string` to lowercase.
425+
- _`toUpper $string`_: Alias for [`strings.ToUpper`](https://pkg.go.dev/strings#ToUpper). Replace lowercase letters in `$string` to uppercase.
426+
427+
Those have been aliased to Sprig functions with the same behaviour as the original docker-gen function:
428+
429+
- _`json $value`_: Alias for Sprig's [`mustToJson`](https://masterminds.github.io/sprig/defaults.html)
430+
- _`parseJson $string`_: Alias for Sprig's [`mustFromJson`](https://masterminds.github.io/sprig/defaults.html).
431+
- _`sha1 $string`_: Alias for Sprig's [`sha1sum`](https://masterminds.github.io/sprig/crypto.html).
432+
429433
---
430434

431435
### Examples

internal/template/template.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ func newTemplate(name string) *template.Template {
102102
"whereLabelDoesNotExist": whereLabelDoesNotExist,
103103
"whereLabelValueMatches": whereLabelValueMatches,
104104

105-
// docker-gen template function aliased to their Sprig clone
105+
// legacy docker-gen template function aliased to their Sprig clone
106106
"json": sprigFuncMap["mustToJson"],
107107
"parseJson": sprigFuncMap["mustFromJson"],
108108
"sha1": sprigFuncMap["sha1sum"],

0 commit comments

Comments
 (0)