2018-04-15 14:35:29 -03:00
|
|
|
package output
|
|
|
|
|
|
|
|
import (
|
2022-02-19 19:31:27 -03:00
|
|
|
"fmt"
|
2018-04-15 14:35:29 -03:00
|
|
|
"io"
|
|
|
|
|
2024-06-03 11:37:24 +02:00
|
|
|
"github.com/go-task/task/v3/internal/logger"
|
2024-03-10 17:11:07 +00:00
|
|
|
"github.com/go-task/task/v3/internal/templater"
|
2023-12-29 20:32:03 +00:00
|
|
|
"github.com/go-task/task/v3/taskfile/ast"
|
2022-02-19 19:31:27 -03:00
|
|
|
)
|
2022-01-14 00:11:47 +00:00
|
|
|
|
2018-04-15 14:35:29 -03:00
|
|
|
type Output interface {
|
2024-03-10 17:11:07 +00:00
|
|
|
WrapWriter(stdOut, stdErr io.Writer, prefix string, cache *templater.Cache) (io.Writer, io.Writer, CloseFunc)
|
2018-04-15 14:35:29 -03:00
|
|
|
}
|
2022-02-19 19:31:27 -03:00
|
|
|
|
2023-03-09 02:34:52 +01:00
|
|
|
type CloseFunc func(err error) error
|
2022-07-06 10:43:32 -03:00
|
|
|
|
2023-12-29 20:32:03 +00:00
|
|
|
// Build the Output for the requested ast.Output.
|
2024-06-03 11:37:24 +02:00
|
|
|
func BuildFor(o *ast.Output, logger *logger.Logger) (Output, error) {
|
2022-02-19 19:31:27 -03:00
|
|
|
switch o.Name {
|
|
|
|
case "interleaved", "":
|
|
|
|
if err := checkOutputGroupUnset(o); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return Interleaved{}, nil
|
|
|
|
case "group":
|
|
|
|
return Group{
|
2023-03-09 02:34:52 +01:00
|
|
|
Begin: o.Group.Begin,
|
|
|
|
End: o.Group.End,
|
|
|
|
ErrorOnly: o.Group.ErrorOnly,
|
2022-02-19 19:31:27 -03:00
|
|
|
}, nil
|
|
|
|
case "prefixed":
|
|
|
|
if err := checkOutputGroupUnset(o); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2024-06-03 11:37:24 +02:00
|
|
|
return NewPrefixed(logger), nil
|
2022-02-19 19:31:27 -03:00
|
|
|
default:
|
|
|
|
return nil, fmt.Errorf(`task: output style %q not recognized`, o.Name)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-29 20:32:03 +00:00
|
|
|
func checkOutputGroupUnset(o *ast.Output) error {
|
2022-02-19 19:31:27 -03:00
|
|
|
if o.Group.IsSet() {
|
|
|
|
return fmt.Errorf("task: output style %q does not support the group begin/end parameter", o.Name)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|