mirror of
https://github.com/go-task/task.git
synced 2026-06-25 13:46:13 +00:00
feat: add json and yaml variable constructors
This commit is contained in:
32
testdata/vars/any2/Taskfile.yml
vendored
32
testdata/vars/any2/Taskfile.yml
vendored
@@ -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
18
testdata/vars/any2/example.json
vendored
Normal 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
9
testdata/vars/any2/example.yaml
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
name: Alice
|
||||
age: 30
|
||||
children:
|
||||
- name: Bob
|
||||
age: 5
|
||||
- name: Charlie
|
||||
age: 3
|
||||
- name: Diane
|
||||
age: 1
|
||||
Reference in New Issue
Block a user