Skip to content

Commit 0e575e9

Browse files
committed
Add --color=false flag to disable colored output
1 parent fb23ba9 commit 0e575e9

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

cmd/task/task.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ func main() {
6060
summary bool
6161
dir string
6262
output string
63+
color bool
6364
)
6465

6566
pflag.BoolVar(&versionFlag, "version", false, "show Task version")
@@ -74,6 +75,7 @@ func main() {
7475
pflag.BoolVar(&summary, "summary", false, "show summary about a task")
7576
pflag.StringVarP(&dir, "dir", "d", "", "sets directory of execution")
7677
pflag.StringVarP(&output, "output", "o", "", "sets output style: [interleaved|group|prefixed]")
78+
pflag.BoolVarP(&color, "color", "c", true, "colored output")
7779
pflag.Parse()
7880

7981
if versionFlag {
@@ -100,6 +102,7 @@ func main() {
100102
Dir: dir,
101103
Dry: dry,
102104
Summary: summary,
105+
Color: color,
103106

104107
Stdin: os.Stdin,
105108
Stdout: os.Stdout,

internal/logger/logger.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,17 @@ type Logger struct {
2525
Stdout io.Writer
2626
Stderr io.Writer
2727
Verbose bool
28+
Color bool
2829
}
2930

3031
// Outf prints stuff to STDOUT.
3132
func (l *Logger) Outf(print PrintFunc, s string, args ...interface{}) {
3233
if len(args) == 0 {
3334
s, args = "%s", []interface{}{s}
3435
}
36+
if !l.Color {
37+
print = Default
38+
}
3539
print(l.Stdout, s+"\n", args...)
3640
}
3741

@@ -47,6 +51,9 @@ func (l *Logger) Errf(print PrintFunc, s string, args ...interface{}) {
4751
if len(args) == 0 {
4852
s, args = "%s", []interface{}{s}
4953
}
54+
if !l.Color {
55+
print = Default
56+
}
5057
print(l.Stderr, s+"\n", args...)
5158
}
5259

task.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ type Executor struct {
3939
Silent bool
4040
Dry bool
4141
Summary bool
42+
Color bool
4243

4344
Stdin io.Reader
4445
Stdout io.Writer
@@ -108,6 +109,7 @@ func (e *Executor) Setup() error {
108109
Stdout: e.Stdout,
109110
Stderr: e.Stderr,
110111
Verbose: e.Verbose,
112+
Color: e.Color,
111113
}
112114

113115
v, err := strconv.ParseFloat(e.Taskfile.Version, 64)

0 commit comments

Comments
 (0)