From eaba1b9cc8b4c38914330de4e2b5cdcf968a8ddb Mon Sep 17 00:00:00 2001 From: Evgeny Abramovich Date: Wed, 29 Jan 2020 10:02:22 +0300 Subject: [PATCH] Added structure for storage information about included tasks --- internal/taskfile/included_taskfile.go | 38 ++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 internal/taskfile/included_taskfile.go diff --git a/internal/taskfile/included_taskfile.go b/internal/taskfile/included_taskfile.go new file mode 100644 index 00000000..3b9c7008 --- /dev/null +++ b/internal/taskfile/included_taskfile.go @@ -0,0 +1,38 @@ +package taskfile + +import "errors" + +var ( + // ErrCantUnmarshalIncludedTaskFile is returned for invalid var YAML. + ErrCantUnmarshalIncludedTaskFile = errors.New("task: can't unmarshal included value") +) + +// IncludedTaskFile represents information about included tasksfile +type IncludedTaskFile struct { + Taskfile string + Dir string +} + +// IncludedTaskFiles represents information about included tasksfiles +type IncludedTaskFiles = map[string]IncludedTaskFile + +// UnmarshalYAML implements yaml.Unmarshaler interface +func (it *IncludedTaskFile) UnmarshalYAML(unmarshal func(interface{}) error) error { + 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 + return nil + } + + return ErrCantUnmarshalIncludedTaskFile +}