1
0
mirror of https://github.com/go-task/task.git synced 2025-11-27 22:38:20 +02:00

Issue #519: Allow includes to be optional

This commit is contained in:
Sally Young
2021-08-11 17:28:44 +01:00
parent 50e5813222
commit 8f80fc4e2c
8 changed files with 93 additions and 1 deletions

View File

@@ -10,6 +10,7 @@ import (
type IncludedTaskfile struct {
Taskfile string
Dir string
Optional bool
AdvancedImport bool
}
@@ -92,12 +93,14 @@ func (it *IncludedTaskfile) UnmarshalYAML(unmarshal func(interface{}) error) err
var includedTaskfile struct {
Taskfile string
Dir string
Optional bool
}
if err := unmarshal(&includedTaskfile); err != nil {
return err
}
it.Dir = includedTaskfile.Dir
it.Taskfile = includedTaskfile.Taskfile
it.Dir = includedTaskfile.Dir
it.Optional = includedTaskfile.Optional
it.AdvancedImport = true
return nil
}

View File

@@ -42,6 +42,7 @@ func Taskfile(dir string, entrypoint string) (*taskfile.Taskfile, error) {
includedTask = taskfile.IncludedTaskfile{
Taskfile: tr.Replace(includedTask.Taskfile),
Dir: tr.Replace(includedTask.Dir),
Optional: includedTask.Optional,
AdvancedImport: includedTask.AdvancedImport,
}
if err := tr.Err(); err != nil {
@@ -56,6 +57,9 @@ func Taskfile(dir string, entrypoint string) (*taskfile.Taskfile, error) {
}
info, err := os.Stat(path)
if err != nil && includedTask.Optional {
return nil
}
if err != nil {
return err
}