output.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package ast
  2. import (
  3. "gopkg.in/yaml.v3"
  4. "github.com/go-task/task/v3/errors"
  5. )
  6. // Output of the Task output
  7. type Output struct {
  8. // Name of the Output.
  9. Name string `yaml:"-"`
  10. // Group specific style
  11. Group OutputGroup
  12. }
  13. // IsSet returns true if and only if a custom output style is set.
  14. func (s *Output) IsSet() bool {
  15. return s.Name != ""
  16. }
  17. func (s *Output) UnmarshalYAML(node *yaml.Node) error {
  18. switch node.Kind {
  19. case yaml.ScalarNode:
  20. var name string
  21. if err := node.Decode(&name); err != nil {
  22. return errors.NewTaskfileDecodeError(err, node)
  23. }
  24. s.Name = name
  25. return nil
  26. case yaml.MappingNode:
  27. var tmp struct {
  28. Group *OutputGroup
  29. }
  30. if err := node.Decode(&tmp); err != nil {
  31. return errors.NewTaskfileDecodeError(err, node)
  32. }
  33. if tmp.Group == nil {
  34. return errors.NewTaskfileDecodeError(nil, node).WithMessage(`output style must have the "group" key when in mapping form`)
  35. }
  36. *s = Output{
  37. Name: "group",
  38. Group: *tmp.Group,
  39. }
  40. return nil
  41. }
  42. return errors.NewTaskfileDecodeError(nil, node).WithTypeMessage("output")
  43. }
  44. // OutputGroup is the style options specific to the Group style.
  45. type OutputGroup struct {
  46. Begin, End string
  47. ErrorOnly bool `yaml:"error_only"`
  48. }
  49. // IsSet returns true if and only if a custom output style is set.
  50. func (g *OutputGroup) IsSet() bool {
  51. if g == nil {
  52. return false
  53. }
  54. return g.Begin != "" || g.End != ""
  55. }