Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions cmd/task/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,7 @@ func run() error {
globals.Set("CLI_SILENT", ast.Var{Value: flags.Silent})
globals.Set("CLI_VERBOSE", ast.Var{Value: flags.Verbose})
globals.Set("CLI_OFFLINE", ast.Var{Value: flags.Offline})
e.Taskfile.Vars.Merge(globals, nil)

e.Taskfile.Vars.ReverseMerge(globals, nil)
if !flags.Watch {
e.InterceptInterruptSignals()
}
Expand Down
31 changes: 30 additions & 1 deletion taskfile/ast/vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func (vars *Vars) ToCacheMap() (m map[string]any) {

// Merge loops over other and merges it values with the variables in vars. If
// the include parameter is not nil and its it is an advanced import, the
// directory is set set to the value of the include parameter.
// directory is set to the value of the include parameter.
func (vars *Vars) Merge(other *Vars, include *Include) {
if vars == nil || vars.om == nil || other == nil {
return
Expand All @@ -133,6 +133,35 @@ func (vars *Vars) Merge(other *Vars, include *Include) {
}
}

// ReverseMerge merges other variables with the existing variables in vars, but
// keeps the other variables first in order. If the include parameter is not
// nil and it is an advanced import, the directory is set to the value of the
// include parameter.
func (vars *Vars) ReverseMerge(other *Vars, include *Include) {
if vars == nil || vars.om == nil || other == nil || other.om == nil {
return
}

newOM := orderedmap.NewOrderedMap[string, Var]()

other.mutex.RLock()
for pair := other.om.Front(); pair != nil; pair = pair.Next() {
val := pair.Value
if include != nil && include.AdvancedImport {
val.Dir = include.Dir
}
newOM.Set(pair.Key, val)
}
other.mutex.RUnlock()

vars.mutex.Lock()
for pair := vars.om.Front(); pair != nil; pair = pair.Next() {
newOM.Set(pair.Key, pair.Value)
}
vars.om = newOM
vars.mutex.Unlock()
}

func (vs *Vars) DeepCopy() *Vars {
if vs == nil {
return nil
Expand Down
Loading