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 -}}"

18
testdata/vars/any2/example.json vendored Normal file
View File

@@ -0,0 +1,18 @@
{
"name": "Alice",
"age": 30,
"children": [
{
"name": "Bob",
"age": 5
},
{
"name": "Charlie",
"age": 3
},
{
"name": "Diane",
"age": 1
}
]
}

9
testdata/vars/any2/example.yaml vendored Normal file
View File

@@ -0,0 +1,9 @@
name: Alice
age: 30
children:
- name: Bob
age: 5
- name: Charlie
age: 3
- name: Diane
age: 1