1
0
mirror of https://github.com/go-task/task.git synced 2025-08-10 22:42:19 +02:00

feat: add ability to call task with variable by reference

This commit is contained in:
Pete Davison
2023-12-29 03:49:12 +00:00
parent c655d90ab3
commit 1f3fca50b3
5 changed files with 37 additions and 20 deletions

View File

@@ -211,6 +211,17 @@ func (e *Executor) compiledTask(call ast.Call, evaluateShVars bool) (*ast.Task,
newCmd.Cmd = r.Replace(cmd.Cmd)
newCmd.Task = r.Replace(cmd.Task)
newCmd.Vars = r.ReplaceVars(cmd.Vars)
// Loop over the command's variables and resolve any references to other variables
err := cmd.Vars.Range(func(k string, v ast.Var) error {
if v.Ref != "" {
refVal := vars.Get(v.Ref)
newCmd.Vars.Set(k, refVal)
}
return nil
})
if err != nil {
return nil, err
}
new.Cmds = append(new.Cmds, newCmd)
}
}