mirror of
https://github.com/go-task/task.git
synced 2025-11-25 22:32:55 +02:00
Refactor variables: Keep order of declaration
This shouldn't have any behavior changes for now. This is a code refactor that should allow us to do further improvements on how variables are handled, specially regarding respecting the declaration order in Taskfiles, which should make it easier for the users. Initial work on #218
This commit is contained in:
22
variables.go
22
variables.go
@@ -50,19 +50,19 @@ func (e *Executor) CompiledTask(call taskfile.Call) (*taskfile.Task, error) {
|
||||
new.Prefix = new.Task
|
||||
}
|
||||
|
||||
new.Env = make(taskfile.Vars, len(e.Taskfile.Env)+len(origTask.Env))
|
||||
for k, v := range r.ReplaceVars(e.Taskfile.Env) {
|
||||
new.Env[k] = v
|
||||
}
|
||||
for k, v := range r.ReplaceVars(origTask.Env) {
|
||||
new.Env[k] = v
|
||||
}
|
||||
for k, v := range new.Env {
|
||||
new.Env = &taskfile.Vars{}
|
||||
new.Env.Merge(r.ReplaceVars(e.Taskfile.Env))
|
||||
new.Env.Merge(r.ReplaceVars(origTask.Env))
|
||||
err = new.Env.Range(func(k string, v taskfile.Var) error {
|
||||
static, err := e.Compiler.HandleDynamicVar(v)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return err
|
||||
}
|
||||
new.Env[k] = taskfile.Var{Static: static}
|
||||
new.Env.Set(k, taskfile.Var{Static: static})
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(origTask.Cmds) > 0 {
|
||||
@@ -103,7 +103,7 @@ func (e *Executor) CompiledTask(call taskfile.Call) (*taskfile.Task, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
vars[strings.ToUpper(checker.Kind())] = taskfile.Var{Live: value}
|
||||
vars.Set(strings.ToUpper(checker.Kind()), taskfile.Var{Live: value})
|
||||
}
|
||||
|
||||
// Adding new variables, requires us to refresh the templaters
|
||||
|
||||
Reference in New Issue
Block a user