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:
11
variables.go
11
variables.go
@@ -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)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user