1
0
mirror of https://github.com/go-task/task.git synced 2025-06-08 23:56:21 +02:00

fix: dynamic vars break with for because of fast-compiled tasks

This commit is contained in:
Pete Davison 2023-12-02 01:00:32 +00:00
parent 4a0414274f
commit 1eeb7d5cf9

View File

@ -156,19 +156,24 @@ func (e *Executor) compiledTask(call taskfile.Call, evaluateShVars bool) (*taskf
if cmd.For.Var != "" { if cmd.For.Var != "" {
if vars != nil { if vars != nil {
v := vars.Get(cmd.For.Var) v := vars.Get(cmd.For.Var)
switch value := v.Value.(type) { // If the variable is dynamic, then it hasn't been resolved yet
case string: // and we can't use it as a list. This happens when fast compiling a task
if cmd.For.Split != "" { // for use in --list or --list-all etc.
list = asAnySlice(strings.Split(value, cmd.For.Split)) if v.Value != nil && v.Sh == "" {
} else { switch value := v.Value.(type) {
list = asAnySlice(strings.Fields(value)) case string:
} if cmd.For.Split != "" {
case []any: list = asAnySlice(strings.Split(value, cmd.For.Split))
list = value } else {
default: list = asAnySlice(strings.Fields(value))
return nil, errors.TaskfileInvalidError{ }
URI: origTask.Location.Taskfile, case []any:
Err: errors.New("var must be a delimiter-separated string or a list"), list = value
default:
return nil, errors.TaskfileInvalidError{
URI: origTask.Location.Taskfile,
Err: errors.New("var must be a delimiter-separated string or a list"),
}
} }
} }
} }