mirror of
https://github.com/go-task/task.git
synced 2025-11-25 22:32:55 +02:00
Merge pull request #39 from smyrman/issue-38
Allow template evaluation when calling a task with vars
This commit is contained in:
@@ -30,13 +30,15 @@ hello:
|
|||||||
generates:
|
generates:
|
||||||
- output.txt
|
- output.txt
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
Options:
|
||||||
`
|
`
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
log.SetFlags(0)
|
log.SetFlags(0)
|
||||||
|
|
||||||
pflag.Usage = func() {
|
pflag.Usage = func() {
|
||||||
fmt.Println(usage)
|
fmt.Print(usage)
|
||||||
pflag.PrintDefaults()
|
pflag.PrintDefaults()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
10
task.go
10
task.go
@@ -237,7 +237,15 @@ func (e *Executor) runCommand(ctx context.Context, task string, i int, vars Vars
|
|||||||
cmd := t.Cmds[i]
|
cmd := t.Cmds[i]
|
||||||
|
|
||||||
if cmd.Cmd == "" {
|
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)
|
c, err := e.ReplaceVariables(cmd.Cmd, task, vars)
|
||||||
|
|||||||
@@ -178,6 +178,7 @@ func TestParams(t *testing.T) {
|
|||||||
{"exclamation.txt", "!\n"},
|
{"exclamation.txt", "!\n"},
|
||||||
{"dep1.txt", "Dependence1\n"},
|
{"dep1.txt", "Dependence1\n"},
|
||||||
{"dep2.txt", "Dependence2\n"},
|
{"dep2.txt", "Dependence2\n"},
|
||||||
|
{"spanish.txt", "¡Holla mundo!\n"},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, f := range files {
|
for _, f := range files {
|
||||||
|
|||||||
4
testdata/params/Taskfile.yml
vendored
4
testdata/params/Taskfile.yml
vendored
@@ -1,4 +1,6 @@
|
|||||||
default:
|
default:
|
||||||
|
vars:
|
||||||
|
SPANISH: ¡Holla mundo!
|
||||||
deps:
|
deps:
|
||||||
- task: write-file
|
- task: write-file
|
||||||
vars: {CONTENT: Dependence1, FILE: dep1.txt}
|
vars: {CONTENT: Dependence1, FILE: dep1.txt}
|
||||||
@@ -11,6 +13,8 @@ default:
|
|||||||
vars: {CONTENT: "$echo 'World'", FILE: world.txt}
|
vars: {CONTENT: "$echo 'World'", FILE: world.txt}
|
||||||
- task: write-file
|
- task: write-file
|
||||||
vars: {CONTENT: "!", FILE: exclamation.txt}
|
vars: {CONTENT: "!", FILE: exclamation.txt}
|
||||||
|
- task: write-file
|
||||||
|
vars: {CONTENT: "{{.SPANISH}}", FILE: spanish.txt}
|
||||||
|
|
||||||
write-file:
|
write-file:
|
||||||
cmds:
|
cmds:
|
||||||
|
|||||||
Reference in New Issue
Block a user