From 1d4473a5cd2b26216a8adf6582bd54d3422faf28 Mon Sep 17 00:00:00 2001 From: Vigilans Date: Wed, 31 Dec 2025 01:17:20 +0800 Subject: [PATCH] feat: add documents for template functions introduced/enhanced in v0.42.3 Signed-off-by: Vigilans --- docs/tpl.md | 47 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 44 insertions(+), 3 deletions(-) diff --git a/docs/tpl.md b/docs/tpl.md index 152dbb51..1dde0ce9 100644 --- a/docs/tpl.md +++ b/docs/tpl.md @@ -52,28 +52,69 @@ The :simple-yaml: `toYaml` function allows you to convert a value to YAML string ### `fromYaml` -The `fromYaml` function allows you to convert a YAML string to a value. When has failed, the template rendering will fail with an error message. +The `fromYaml` function allows you to convert a YAML string to a value (map). When has failed, the template rendering will fail with an error message. ```shell {{ $value := $yamlString | fromYaml }} ``` +### `fromYamlArray` + +> Introduced in [:material-tag: v0.42.3](https://github.com/helmwave/helmwave/releases/tag/v0.42.3) + +The `fromYamlArray` function allows you to parse a YAML array (single document) into a list. When has failed, the template rendering will fail with an error message. + +```shell +{{ $list := "[1, 2, 3]" | fromYamlArray }} +{{ $list := "- a\n- b\n- c" | fromYamlArray }} +``` + +### `fromYamlAll` + +> Introduced in [:material-tag: v0.42.3](https://github.com/helmwave/helmwave/releases/tag/v0.42.3) + +The `fromYamlAll` function allows you to parse multiple YAML documents (separated by `---`) into a list. When has failed, the template rendering will fail with an error message. + +```shell +{{ $docs := "---\napiVersion: v1\n---\nkind: ConfigMap" | fromYamlAll }} +``` + ### `exec` The `exec` function allows you to run a command, returning the stdout of the command. When the command fails, the template rendering will fail with an error message. ```shell -{{ $cmdOutpot := exec "./mycmd" (list "arg1" "arg2" "--flag1") }} +{{ $cmdOutput := exec "./mycmd" (list "arg1" "arg2" "--flag1") }} +``` + +Since v0.42.3, can be called in 4 ways: + +```shell +{{ exec "command arg1 arg2" }} +{{ exec "command" (list "arg1" "arg2") }} +{{ "input" | exec "command arg1 arg2" }} +{{ "input" | exec "command" (list "arg1" "arg2") }} ``` +- Command string with arguments (split by shell-like rules) +- Command with explicit argument list +- Piped input with command string +- Piped input with explicit argument list + ### `setValueAtPath` -The `setValueAtPath` function allows you to set a value at a path. When has failed, the template rendering will fail with an error message. +The `setValueAtPath` function allows you to set a value at a dot-separated path. When has failed, the template rendering will fail with an error message. ```shell {{ $value | setValueAtPath "path.key" $newValue }} ``` +Since v0.42.3, numeric indices are supported for arrays: + +```shell +{{ $value | setValueAtPath "items.0.name" "first-item" }} +``` + ### `requiredEnv` The `requiredEnv` function allows you to declare a particular environment variable as required for template rendering.