1
0
mirror of https://github.com/go-task/task.git synced 2025-01-06 03:53:54 +02:00

add vars to included taskfiles

This commit is contained in:
Dan Ballweg 2022-02-23 16:53:46 -06:00
parent d8555e5a5d
commit 292cf75836
2 changed files with 10 additions and 0 deletions

View File

@ -12,6 +12,7 @@ type IncludedTaskfile struct {
Dir string
Optional bool
AdvancedImport bool
Vars *Vars
}
// IncludedTaskfiles represents information about included tasksfiles
@ -94,6 +95,7 @@ func (it *IncludedTaskfile) UnmarshalYAML(unmarshal func(interface{}) error) err
Taskfile string
Dir string
Optional bool
Vars *Vars
}
if err := unmarshal(&includedTaskfile); err != nil {
return err
@ -102,5 +104,6 @@ func (it *IncludedTaskfile) UnmarshalYAML(unmarshal func(interface{}) error) err
it.Dir = includedTaskfile.Dir
it.Optional = includedTaskfile.Optional
it.AdvancedImport = true
it.Vars = includedTaskfile.Vars
return nil
}

View File

@ -62,6 +62,7 @@ func Taskfile(dir string, entrypoint string) (*taskfile.Taskfile, error) {
Dir: tr.Replace(includedTask.Dir),
Optional: includedTask.Optional,
AdvancedImport: includedTask.AdvancedImport,
Vars: includedTask.Vars,
}
if err := tr.Err(); err != nil {
return err
@ -109,6 +110,12 @@ func Taskfile(dir string, entrypoint string) (*taskfile.Taskfile, error) {
}
for _, task := range includedTaskfile.Tasks {
if includedTask.Vars != nil {
if task.Vars == nil {
task.Vars = &taskfile.Vars{}
}
task.Vars.Merge(includedTask.Vars)
}
if !filepath.IsAbs(task.Dir) {
task.Dir = filepath.Join(includedTask.Dir, task.Dir)
}