mirror of
https://github.com/go-task/task.git
synced 2025-03-05 15:05:42 +02:00
* feat: add references to the base code instead of the maps experiment * feat: add template functions to ref resolver * feat: tests * docs: variable references * feat: remove json and yaml keys from map variable experiment * chore: typo
75 lines
1.4 KiB
YAML
75 lines
1.4 KiB
YAML
version: '3'
|
|
|
|
vars:
|
|
GLOBAL_VAR: [1, 2, 2, 2, 3, 3, 4, 5]
|
|
|
|
tasks:
|
|
default:
|
|
- task: ref-cmd
|
|
- task: ref-dep
|
|
- task: ref-resolver
|
|
- task: ref-resolver-sh
|
|
|
|
ref-cmd:
|
|
vars:
|
|
VAR_REF:
|
|
ref: .GLOBAL_VAR
|
|
cmds:
|
|
- task: print-first
|
|
vars:
|
|
VAR:
|
|
ref: .VAR_REF
|
|
|
|
ref-dep:
|
|
vars:
|
|
VAR_REF:
|
|
ref: .GLOBAL_VAR
|
|
deps:
|
|
- task: print-first
|
|
vars:
|
|
VAR:
|
|
ref: .VAR_REF
|
|
|
|
ref-resolver:
|
|
vars:
|
|
VAR_REF:
|
|
ref: .GLOBAL_VAR
|
|
cmds:
|
|
- task: print-var
|
|
vars:
|
|
VAR:
|
|
ref: (index .VAR_REF 0)
|
|
|
|
ref-resolver-sh:
|
|
vars:
|
|
JSON_STRING:
|
|
sh: echo '{"name":"Alice","age":30,"children":[{"name":"Bob","age":5},{"name":"Charlie","age":3},{"name":"Diane","age":1}]}'
|
|
JSON:
|
|
ref: "fromJson .JSON_STRING"
|
|
VAR_REF:
|
|
ref: .JSON
|
|
cmds:
|
|
- task: print-story
|
|
vars:
|
|
VAR:
|
|
ref: .VAR_REF
|
|
|
|
print-var:
|
|
cmds:
|
|
- echo "{{.VAR}}"
|
|
|
|
print-first:
|
|
cmds:
|
|
- echo "{{index .VAR 0}}"
|
|
|
|
print-story:
|
|
cmds:
|
|
- >-
|
|
echo "{{.VAR.name}} has {{len .VAR.children}} children called
|
|
{{- $children := .VAR.children -}}
|
|
{{- range $i, $child := $children -}}
|
|
{{- if lt $i (sub (len $children) 1)}} {{$child.name -}},
|
|
{{- else}} and {{$child.name -}}
|
|
{{- end -}}
|
|
{{- end -}}"
|