1
0
mirror of https://github.com/go-task/task.git synced 2025-03-05 15:05:42 +02:00

Allow template evaluation in parameters

When passing variables to a sub-task, allow template evaluation
within the passed-on variables.
This commit is contained in:
Sindre Røkenes Myren 2017-07-06 18:40:21 +02:00 committed by Sindre Myren
parent 774ef61c2f
commit 2f9381065d
3 changed files with 14 additions and 1 deletions

10
task.go
View File

@ -237,7 +237,15 @@ func (e *Executor) runCommand(ctx context.Context, task string, i int, vars Vars
cmd := t.Cmds[i]
if cmd.Cmd == "" {
return e.RunTask(ctx, cmd.Task, cmd.Vars)
cmdVars := make(Vars, len(cmd.Vars))
for k, v := range cmd.Vars {
v, err := e.ReplaceVariables(v, task, vars)
if err != nil {
return err
}
cmdVars[k] = v
}
return e.RunTask(ctx, cmd.Task, cmdVars)
}
c, err := e.ReplaceVariables(cmd.Cmd, task, vars)

View File

@ -178,6 +178,7 @@ func TestParams(t *testing.T) {
{"exclamation.txt", "!\n"},
{"dep1.txt", "Dependence1\n"},
{"dep2.txt", "Dependence2\n"},
{"spanish.txt", "¡Holla mundo!\n"},
}
for _, f := range files {

View File

@ -1,4 +1,6 @@
default:
vars:
SPANISH: ¡Holla mundo!
deps:
- task: write-file
vars: {CONTENT: Dependence1, FILE: dep1.txt}
@ -11,6 +13,8 @@ default:
vars: {CONTENT: "$echo 'World'", FILE: world.txt}
- task: write-file
vars: {CONTENT: "!", FILE: exclamation.txt}
- task: write-file
vars: {CONTENT: "{{.SPANISH}}", FILE: spanish.txt}
write-file:
cmds: