2020-01-29 09:02:22 +02:00
|
|
|
package taskfile
|
|
|
|
|
|
|
|
import "errors"
|
|
|
|
|
|
|
|
var (
|
2020-02-12 09:42:00 +02:00
|
|
|
// ErrCantUnmarshalIncludedTaskfile is returned for invalid var YAML.
|
|
|
|
ErrCantUnmarshalIncludedTaskfile = errors.New("task: can't unmarshal included value")
|
2020-01-29 09:02:22 +02:00
|
|
|
)
|
|
|
|
|
2020-02-12 09:42:00 +02:00
|
|
|
// IncludedTaskfile represents information about included tasksfile
|
|
|
|
type IncludedTaskfile struct {
|
2020-02-15 16:24:06 +02:00
|
|
|
Taskfile string
|
|
|
|
Dir string
|
|
|
|
AdvancedImport bool
|
2020-01-29 09:02:22 +02:00
|
|
|
}
|
|
|
|
|
2020-02-12 09:42:00 +02:00
|
|
|
// IncludedTaskfiles represents information about included tasksfiles
|
|
|
|
type IncludedTaskfiles = map[string]IncludedTaskfile
|
2020-01-29 09:02:22 +02:00
|
|
|
|
|
|
|
// UnmarshalYAML implements yaml.Unmarshaler interface
|
2020-02-12 09:42:00 +02:00
|
|
|
func (it *IncludedTaskfile) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
2020-01-29 09:02:22 +02:00
|
|
|
var str string
|
|
|
|
if err := unmarshal(&str); err == nil {
|
|
|
|
it.Taskfile = str
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
var includedTaskfile struct {
|
|
|
|
Taskfile string
|
|
|
|
Dir string
|
|
|
|
}
|
|
|
|
if err := unmarshal(&includedTaskfile); err == nil {
|
|
|
|
it.Dir = includedTaskfile.Dir
|
|
|
|
it.Taskfile = includedTaskfile.Taskfile
|
2020-02-15 16:24:06 +02:00
|
|
|
it.AdvancedImport = true
|
2020-01-29 09:02:22 +02:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-02-12 09:42:00 +02:00
|
|
|
return ErrCantUnmarshalIncludedTaskfile
|
2020-01-29 09:02:22 +02:00
|
|
|
}
|