Skip to content

Commit 2f93810

Browse files
committed
Allow template evaluation in parameters
When passing variables to a sub-task, allow template evaluation within the passed-on variables.
1 parent 774ef61 commit 2f93810

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

task.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,15 @@ func (e *Executor) runCommand(ctx context.Context, task string, i int, vars Vars
237237
cmd := t.Cmds[i]
238238

239239
if cmd.Cmd == "" {
240-
return e.RunTask(ctx, cmd.Task, cmd.Vars)
240+
cmdVars := make(Vars, len(cmd.Vars))
241+
for k, v := range cmd.Vars {
242+
v, err := e.ReplaceVariables(v, task, vars)
243+
if err != nil {
244+
return err
245+
}
246+
cmdVars[k] = v
247+
}
248+
return e.RunTask(ctx, cmd.Task, cmdVars)
241249
}
242250

243251
c, err := e.ReplaceVariables(cmd.Cmd, task, vars)

task_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ func TestParams(t *testing.T) {
178178
{"exclamation.txt", "!\n"},
179179
{"dep1.txt", "Dependence1\n"},
180180
{"dep2.txt", "Dependence2\n"},
181+
{"spanish.txt", "¡Holla mundo!\n"},
181182
}
182183

183184
for _, f := range files {

testdata/params/Taskfile.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
default:
2+
vars:
3+
SPANISH: ¡Holla mundo!
24
deps:
35
- task: write-file
46
vars: {CONTENT: Dependence1, FILE: dep1.txt}
@@ -11,6 +13,8 @@ default:
1113
vars: {CONTENT: "$echo 'World'", FILE: world.txt}
1214
- task: write-file
1315
vars: {CONTENT: "!", FILE: exclamation.txt}
16+
- task: write-file
17+
vars: {CONTENT: "{{.SPANISH}}", FILE: spanish.txt}
1418

1519
write-file:
1620
cmds:

0 commit comments

Comments
 (0)