dep.go 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package ast
  2. import (
  3. "gopkg.in/yaml.v3"
  4. "github.com/go-task/task/v3/errors"
  5. )
  6. // Dep is a task dependency
  7. type Dep struct {
  8. Task string
  9. For *For
  10. Vars *Vars
  11. Silent bool
  12. }
  13. func (d *Dep) DeepCopy() *Dep {
  14. if d == nil {
  15. return nil
  16. }
  17. return &Dep{
  18. Task: d.Task,
  19. For: d.For.DeepCopy(),
  20. Vars: d.Vars.DeepCopy(),
  21. Silent: d.Silent,
  22. }
  23. }
  24. func (d *Dep) UnmarshalYAML(node *yaml.Node) error {
  25. switch node.Kind {
  26. case yaml.ScalarNode:
  27. var task string
  28. if err := node.Decode(&task); err != nil {
  29. return errors.NewTaskfileDecodeError(err, node)
  30. }
  31. d.Task = task
  32. return nil
  33. case yaml.MappingNode:
  34. var taskCall struct {
  35. Task string
  36. For *For
  37. Vars *Vars
  38. Silent bool
  39. }
  40. if err := node.Decode(&taskCall); err != nil {
  41. return errors.NewTaskfileDecodeError(err, node)
  42. }
  43. d.Task = taskCall.Task
  44. d.For = taskCall.For
  45. d.Vars = taskCall.Vars
  46. d.Silent = taskCall.Silent
  47. return nil
  48. }
  49. return errors.NewTaskfileDecodeError(nil, node).WithTypeMessage("dependency")
  50. }