1
0

output.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package output
  2. import (
  3. "fmt"
  4. "io"
  5. "github.com/go-task/task/v3/internal/logger"
  6. "github.com/go-task/task/v3/internal/templater"
  7. "github.com/go-task/task/v3/taskfile/ast"
  8. )
  9. type Output interface {
  10. WrapWriter(stdOut, stdErr io.Writer, prefix string, cache *templater.Cache) (io.Writer, io.Writer, CloseFunc)
  11. }
  12. type CloseFunc func(err error) error
  13. // Build the Output for the requested ast.Output.
  14. func BuildFor(o *ast.Output, logger *logger.Logger) (Output, error) {
  15. switch o.Name {
  16. case "interleaved", "":
  17. if err := checkOutputGroupUnset(o); err != nil {
  18. return nil, err
  19. }
  20. return Interleaved{}, nil
  21. case "group":
  22. return Group{
  23. Begin: o.Group.Begin,
  24. End: o.Group.End,
  25. ErrorOnly: o.Group.ErrorOnly,
  26. }, nil
  27. case "prefixed":
  28. if err := checkOutputGroupUnset(o); err != nil {
  29. return nil, err
  30. }
  31. return NewPrefixed(logger), nil
  32. default:
  33. return nil, fmt.Errorf(`task: output style %q not recognized`, o.Name)
  34. }
  35. }
  36. func checkOutputGroupUnset(o *ast.Output) error {
  37. if o.Group.IsSet() {
  38. return fmt.Errorf("task: output style %q does not support the group begin/end parameter", o.Name)
  39. }
  40. return nil
  41. }