feat: add json and yaml variable constructors

This commit is contained in:
Pete Davison
2023-12-23 04:59:44 +00:00
parent 2ccf80713d
commit c655d90ab3
5 changed files with 86 additions and 4 deletions

View File

@@ -19,3 +19,35 @@ tasks:
{{- else}} and {{$child.name -}}
{{- end -}}
{{- end -}}"
json:
vars:
JSON_STRING:
sh: cat example.json
JSON:
json: "{{.JSON_STRING}}"
cmds:
- >-
echo "{{.JSON.name}} has {{len .JSON.children}} children called
{{- $children := .JSON.children -}}
{{- range $i, $child := $children -}}
{{- if lt $i (sub (len $children) 1)}} {{$child.name -}},
{{- else}} and {{$child.name -}}
{{- end -}}
{{- end -}}"
yaml:
vars:
YAML_STRING:
sh: cat example.yaml
YAML:
yaml: "{{.YAML_STRING}}"
cmds:
- >-
echo "{{.YAML.name}} has {{len .YAML.children}} children called
{{- $children := .YAML.children -}}
{{- range $i, $child := $children -}}
{{- if lt $i (sub (len $children) 1)}} {{$child.name -}},
{{- else}} and {{$child.name -}}
{{- end -}}
{{- end -}}"