mirror of
https://github.com/go-task/task.git
synced 2025-08-10 22:42:19 +02:00
feat: for
This commit is contained in:
committed by
Andrey Nering
parent
7ece04e996
commit
7ff1b1795e
93
testdata/for/Taskfile.yml
vendored
Normal file
93
testdata/for/Taskfile.yml
vendored
Normal file
@@ -0,0 +1,93 @@
|
||||
version: "3"
|
||||
|
||||
tasks:
|
||||
# Loop over a list of values
|
||||
loop-explicit:
|
||||
cmds:
|
||||
- for: ["a", "b", "c"]
|
||||
cmd: echo "{{.ITEM}}"
|
||||
|
||||
# Loop over the task's sources
|
||||
loop-sources:
|
||||
sources:
|
||||
- foo.txt
|
||||
- bar.txt
|
||||
cmds:
|
||||
- for: source
|
||||
cmd: cat "{{.ITEM}}"
|
||||
|
||||
# Loop over the task's sources when globbed
|
||||
loop-sources-glob:
|
||||
sources:
|
||||
- "*.txt"
|
||||
cmds:
|
||||
- for: source
|
||||
cmd: cat "{{.ITEM}}"
|
||||
|
||||
# Loop over the contents of a variable
|
||||
loop-vars:
|
||||
vars:
|
||||
FOO: foo.txt,bar.txt
|
||||
cmds:
|
||||
- for:
|
||||
var: FOO
|
||||
split: ","
|
||||
cmd: cat "{{.ITEM}}"
|
||||
|
||||
# Loop over the output of a command (auto splits on " ")
|
||||
loop-vars-sh:
|
||||
vars:
|
||||
FOO:
|
||||
sh: ls *.txt
|
||||
cmds:
|
||||
- for:
|
||||
var: FOO
|
||||
cmd: cat "{{.ITEM}}"
|
||||
|
||||
# Loop over another task
|
||||
loop-task:
|
||||
vars:
|
||||
FOO: foo.txt bar.txt
|
||||
cmds:
|
||||
- for:
|
||||
var: FOO
|
||||
task: looped-task
|
||||
vars:
|
||||
FILE: "{{.ITEM}}"
|
||||
|
||||
# Loop over another task with the variable named differently
|
||||
loop-task-as:
|
||||
vars:
|
||||
FOO: foo.txt bar.txt
|
||||
cmds:
|
||||
- for:
|
||||
var: FOO
|
||||
as: FILE
|
||||
task: looped-task
|
||||
vars:
|
||||
FILE: "{{.FILE}}"
|
||||
|
||||
# Loop over different tasks using the variable
|
||||
loop-different-tasks:
|
||||
vars:
|
||||
FOO: "1 2 3"
|
||||
cmds:
|
||||
- for:
|
||||
var: FOO
|
||||
task: task-{{.ITEM}}
|
||||
|
||||
looped-task:
|
||||
internal: true
|
||||
cmd: cat "{{.FILE}}"
|
||||
|
||||
task-1:
|
||||
internal: true
|
||||
cmd: echo "1"
|
||||
|
||||
task-2:
|
||||
internal: true
|
||||
cmd: echo "2"
|
||||
|
||||
task-3:
|
||||
internal: true
|
||||
cmd: echo "3"
|
1
testdata/for/bar.txt
vendored
Normal file
1
testdata/for/bar.txt
vendored
Normal file
@@ -0,0 +1 @@
|
||||
bar
|
1
testdata/for/foo.txt
vendored
Normal file
1
testdata/for/foo.txt
vendored
Normal file
@@ -0,0 +1 @@
|
||||
foo
|
Reference in New Issue
Block a user