From 8efc38ad826db4c08ef671708b286c3175f845d8 Mon Sep 17 00:00:00 2001 From: Andrey Nering Date: Sun, 26 May 2019 18:36:39 -0300 Subject: [PATCH 1/4] Use colors for some output messages --- cmd/task/task.go | 6 +++-- go.mod | 3 ++- go.sum | 8 ++++++ help.go | 5 ++-- internal/compiler/v1/compiler_v1.go | 2 +- internal/compiler/v2/compiler_v2.go | 2 +- internal/logger/logger.go | 38 ++++++++++++++++++++++------- internal/summary/summary.go | 28 ++++++++++----------- task.go | 10 ++++---- task_test.go | 2 +- watch.go | 13 +++++----- 11 files changed, 75 insertions(+), 42 deletions(-) diff --git a/cmd/task/task.go b/cmd/task/task.go index 4070e1b9..e93727f6 100644 --- a/cmd/task/task.go +++ b/cmd/task/task.go @@ -9,6 +9,7 @@ import ( "github.com/go-task/task/v2" "github.com/go-task/task/v2/internal/args" + "github.com/go-task/task/v2/internal/logger" "github.com/spf13/pflag" ) @@ -117,7 +118,7 @@ func main() { arguments := pflag.Args() if len(arguments) == 0 { - log.Println("task: No argument given, trying default task") + e.Logger.Errf(logger.Yellow, "task: No argument given, trying default task") arguments = []string{"default"} } @@ -139,7 +140,8 @@ func main() { } if err := e.Run(ctx, calls...); err != nil { - log.Fatal(err) + e.Logger.Errf(logger.Red, "%v", err) + os.Exit(1) } } diff --git a/go.mod b/go.mod index 33ddcd46..7074204a 100644 --- a/go.mod +++ b/go.mod @@ -5,10 +5,12 @@ require ( github.com/Masterminds/sprig v2.16.0+incompatible github.com/aokoli/goutils v1.0.1 // indirect github.com/davecgh/go-spew v1.1.1 // indirect + github.com/fatih/color v1.7.0 github.com/google/uuid v1.0.0 // indirect github.com/huandu/xstrings v1.1.0 // indirect github.com/imdario/mergo v0.3.6 // indirect github.com/kr/pretty v0.1.0 // indirect + github.com/mattn/go-colorable v0.1.2 // indirect github.com/mattn/go-zglob v0.0.1 github.com/mitchellh/go-homedir v1.0.0 github.com/radovskyb/watcher v1.0.5 @@ -17,7 +19,6 @@ require ( golang.org/x/crypto v0.0.0-20180830192347-182538f80094 // indirect golang.org/x/net v0.0.0-20180826012351-8a410e7b638d // indirect golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f - golang.org/x/sys v0.0.0-20180831094639-fa5fdf94c789 // indirect gopkg.in/yaml.v2 v2.2.1 mvdan.cc/sh v2.6.4+incompatible ) diff --git a/go.sum b/go.sum index 18f0ea37..d4448452 100644 --- a/go.sum +++ b/go.sum @@ -7,6 +7,8 @@ github.com/aokoli/goutils v1.0.1/go.mod h1:SijmP0QR8LtwsmDs8Yii5Z/S4trXFGFC2oO5g github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys= +github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= github.com/google/uuid v1.0.0 h1:b4Gk+7WdP/d3HZH8EJsZpvV7EtDOgaZLtnaNGIu1adA= github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/huandu/xstrings v1.1.0 h1:9oZY6Z/H3A1gytJxzuicbmV5QoR8M1TAPcn9WTg7vqg= @@ -18,6 +20,10 @@ github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORN github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/mattn/go-colorable v0.1.2 h1:/bC9yWikZXAL9uJdulbSfyVNIR3n3trXl+v8+1sx8mU= +github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= +github.com/mattn/go-isatty v0.0.8 h1:HLtExJ+uU2HOZ+wI0Tt5DtUDrx8yhUqDcp7fYERX4CE= +github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= github.com/mattn/go-zglob v0.0.1 h1:xsEx/XUoVlI6yXjqBK062zYhRTZltCNmYPx6v+8DNaY= github.com/mattn/go-zglob v0.0.1/go.mod h1:9fxibJccNxU2cnpIKLRRFA7zX7qhkJIQWBb449FYHOo= github.com/mitchellh/go-homedir v1.0.0 h1:vKb8ShqSby24Yrqr/yDYkuFz8d0WUjys40rvnGC8aR0= @@ -39,6 +45,8 @@ golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f h1:wMNYb4v58l5UBM7MYRLPG6Zh golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180831094639-fa5fdf94c789 h1:T8D7l6WB3tLu+VpKvw06ieD/OhBi1XpJmG1U/FtttZg= golang.org/x/sys v0.0.0-20180831094639-fa5fdf94c789/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223 h1:DH4skfRX4EBpamg7iV4ZlCpblAHI6s6TDM39bFZumv8= +golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v2 v2.2.1 h1:mUhvW9EsL+naU5Q3cakzfE91YhliOondGd6ZrsDBHQE= diff --git a/help.go b/help.go index 79417609..66bdf709 100644 --- a/help.go +++ b/help.go @@ -5,6 +5,7 @@ import ( "sort" "text/tabwriter" + "github.com/go-task/task/v2/internal/logger" "github.com/go-task/task/v2/internal/taskfile" ) @@ -12,10 +13,10 @@ import ( func (e *Executor) PrintTasksHelp() { tasks := e.tasksWithDesc() if len(tasks) == 0 { - e.Logger.Outf("task: No tasks with description available") + e.Logger.Outf(logger.Yellow, "task: No tasks with description available") return } - e.Logger.Outf("task: Available tasks for this project:") + e.Logger.Outf(logger.Default, "task: Available tasks for this project:") // Format in tab-separated columns with a tab stop of 8. w := tabwriter.NewWriter(e.Stdout, 0, 8, 0, '\t', 0) diff --git a/internal/compiler/v1/compiler_v1.go b/internal/compiler/v1/compiler_v1.go index 7b3bb703..295670e6 100644 --- a/internal/compiler/v1/compiler_v1.go +++ b/internal/compiler/v1/compiler_v1.go @@ -131,7 +131,7 @@ func (c *CompilerV1) HandleDynamicVar(v taskfile.Var) (string, error) { result := strings.TrimSuffix(stdout.String(), "\n") c.dynamicCache[v.Sh] = result - c.Logger.VerboseErrf(`task: dynamic variable: '%s' result: '%s'`, v.Sh, result) + c.Logger.VerboseErrf(logger.Magenta, `task: dynamic variable: '%s' result: '%s'`, v.Sh, result) return result, nil } diff --git a/internal/compiler/v2/compiler_v2.go b/internal/compiler/v2/compiler_v2.go index c61b4b43..e2399f33 100644 --- a/internal/compiler/v2/compiler_v2.go +++ b/internal/compiler/v2/compiler_v2.go @@ -103,7 +103,7 @@ func (c *CompilerV2) HandleDynamicVar(v taskfile.Var) (string, error) { result := strings.TrimSuffix(stdout.String(), "\n") c.dynamicCache[v.Sh] = result - c.Logger.VerboseErrf(`task: dynamic variable: '%s' result: '%s'`, v.Sh, result) + c.Logger.VerboseErrf(logger.Magenta, `task: dynamic variable: '%s' result: '%s'`, v.Sh, result) return result, nil } diff --git a/internal/logger/logger.go b/internal/logger/logger.go index 85c971d4..17487b24 100644 --- a/internal/logger/logger.go +++ b/internal/logger/logger.go @@ -1,38 +1,58 @@ package logger import ( - "fmt" "io" + + "github.com/fatih/color" ) +type PrintFunc func(io.Writer, string, ...interface{}) + +var ( + Default PrintFunc = color.New(color.Reset).FprintfFunc() + Bold PrintFunc = color.New(color.Bold).FprintfFunc() + Blue PrintFunc = color.New(color.FgBlue, color.Bold).FprintfFunc() + Green PrintFunc = color.New(color.FgGreen, color.Bold).FprintfFunc() + Cyan PrintFunc = color.New(color.FgCyan, color.Bold).FprintfFunc() + Yellow PrintFunc = color.New(color.FgYellow, color.Bold).FprintfFunc() + Magenta PrintFunc = color.New(color.FgMagenta, color.Bold).FprintfFunc() + Red PrintFunc = color.New(color.FgRed, color.Bold).FprintfFunc() +) + +// Logger is just a wrapper that prints stuff to STDOUT or STDERR, +// with optional color. type Logger struct { Stdout io.Writer Stderr io.Writer Verbose bool } -func (l *Logger) Outf(s string, args ...interface{}) { +// Outf prints stuff to STDOUT. +func (l *Logger) Outf(print PrintFunc, s string, args ...interface{}) { if len(args) == 0 { s, args = "%s", []interface{}{s} } - fmt.Fprintf(l.Stdout, s+"\n", args...) + print(l.Stdout, s+"\n", args...) } -func (l *Logger) VerboseOutf(s string, args ...interface{}) { +// VerboseOutf prints stuff to STDOUT if verbose mode is enabled. +func (l *Logger) VerboseOutf(print PrintFunc, s string, args ...interface{}) { if l.Verbose { - l.Outf(s, args...) + l.Outf(print, s, args...) } } -func (l *Logger) Errf(s string, args ...interface{}) { +// Errf prints stuff to STDERR. +func (l *Logger) Errf(print PrintFunc, s string, args ...interface{}) { if len(args) == 0 { s, args = "%s", []interface{}{s} } - fmt.Fprintf(l.Stderr, s+"\n", args...) + print(l.Stderr, s+"\n", args...) } -func (l *Logger) VerboseErrf(s string, args ...interface{}) { +// VerboseErrf prints stuff to STDERR if verbose mode is enabled. +func (l *Logger) VerboseErrf(print PrintFunc, s string, args ...interface{}) { if l.Verbose { - l.Errf(s, args...) + l.Errf(print, s, args...) } } diff --git a/internal/summary/summary.go b/internal/summary/summary.go index 655ec76c..7c893293 100644 --- a/internal/summary/summary.go +++ b/internal/summary/summary.go @@ -20,8 +20,8 @@ func printSpaceBetweenSummaries(l *logger.Logger, i int) { return } - l.Outf("") - l.Outf("") + l.Outf(logger.Default, "") + l.Outf(logger.Default, "") } func PrintTask(l *logger.Logger, t *taskfile.Task) { @@ -50,14 +50,14 @@ func printTaskSummary(l *logger.Logger, t *taskfile.Task) { for i, line := range lines { notLastLine := i+1 < len(lines) if notLastLine || line != "" { - l.Outf(line) + l.Outf(logger.Default, line) } } } func printTaskName(l *logger.Logger, t *taskfile.Task) { - l.Outf("task: %s", t.Task) - l.Outf("") + l.Outf(logger.Default, "task: %s", t.Task) + l.Outf(logger.Default, "") } func hasDescription(t *taskfile.Task) bool { @@ -65,11 +65,11 @@ func hasDescription(t *taskfile.Task) bool { } func printTaskDescription(l *logger.Logger, t *taskfile.Task) { - l.Outf(t.Desc) + l.Outf(logger.Default, t.Desc) } func printNoDescriptionOrSummary(l *logger.Logger) { - l.Outf("(task does not have description or summary)") + l.Outf(logger.Default, "(task does not have description or summary)") } func printTaskDependencies(l *logger.Logger, t *taskfile.Task) { @@ -77,11 +77,11 @@ func printTaskDependencies(l *logger.Logger, t *taskfile.Task) { return } - l.Outf("") - l.Outf("dependencies:") + l.Outf(logger.Default, "") + l.Outf(logger.Default, "dependencies:") for _, d := range t.Deps { - l.Outf(" - %s", d.Task) + l.Outf(logger.Default, " - %s", d.Task) } } @@ -90,14 +90,14 @@ func printTaskCommands(l *logger.Logger, t *taskfile.Task) { return } - l.Outf("") - l.Outf("commands:") + l.Outf(logger.Default, "") + l.Outf(logger.Default, "commands:") for _, c := range t.Cmds { isCommand := c.Cmd != "" if isCommand { - l.Outf(" - %s", c.Cmd) + l.Outf(logger.Default, " - %s", c.Cmd) } else { - l.Outf(" - Task: %s", c.Task) + l.Outf(logger.Default, " - Task: %s", c.Task) } } } diff --git a/task.go b/task.go index 2df08c2c..b7a2dec4 100644 --- a/task.go +++ b/task.go @@ -194,7 +194,7 @@ func (e *Executor) RunTask(ctx context.Context, call taskfile.Call) error { } if upToDate { if !e.Silent { - e.Logger.Errf(`task: Task "%s" is up to date`, t.Task) + e.Logger.Errf(logger.Magenta, `task: Task "%s" is up to date`, t.Task) } return nil } @@ -203,11 +203,11 @@ func (e *Executor) RunTask(ctx context.Context, call taskfile.Call) error { for i := range t.Cmds { if err := e.runCommand(ctx, t, call, i); err != nil { if err2 := e.statusOnError(t); err2 != nil { - e.Logger.VerboseErrf("task: error cleaning status on error: %v", err2) + e.Logger.VerboseErrf(logger.Yellow, "task: error cleaning status on error: %v", err2) } if execext.IsExitError(err) && t.IgnoreError { - e.Logger.VerboseErrf("task: task error ignored: %v", err) + e.Logger.VerboseErrf(logger.Yellow, "task: task error ignored: %v", err) continue } @@ -239,7 +239,7 @@ func (e *Executor) runCommand(ctx context.Context, t *taskfile.Task, call taskfi return e.RunTask(ctx, taskfile.Call{Task: cmd.Task, Vars: cmd.Vars}) case cmd.Cmd != "": if e.Verbose || (!cmd.Silent && !t.Silent && !e.Silent) { - e.Logger.Errf(cmd.Cmd) + e.Logger.Errf(logger.Green, "task: %s", cmd.Cmd) } if e.Dry { @@ -270,7 +270,7 @@ func (e *Executor) runCommand(ctx context.Context, t *taskfile.Task, call taskfi Stderr: stdErr, }) if execext.IsExitError(err) && cmd.IgnoreError { - e.Logger.VerboseErrf("task: command error ignored: %v", err) + e.Logger.VerboseErrf(logger.Yellow, "task: command error ignored: %v", err) return nil } return err diff --git a/task_test.go b/task_test.go index e2278dc5..0d929420 100644 --- a/task_test.go +++ b/task_test.go @@ -470,7 +470,7 @@ func TestDry(t *testing.T) { assert.NoError(t, e.Setup()) assert.NoError(t, e.Run(context.Background(), taskfile.Call{Task: "build"})) - assert.Equal(t, "touch file.txt", strings.TrimSpace(buff.String())) + assert.Equal(t, "task: touch file.txt", strings.TrimSpace(buff.String())) if _, err := os.Stat(file); err == nil { t.Errorf("File should not exist %s", file) } diff --git a/watch.go b/watch.go index 14eda036..019e4bcc 100644 --- a/watch.go +++ b/watch.go @@ -8,6 +8,7 @@ import ( "syscall" "time" + "github.com/go-task/task/v2/internal/logger" "github.com/go-task/task/v2/internal/taskfile" "github.com/mattn/go-zglob" "github.com/radovskyb/watcher" @@ -24,14 +25,14 @@ func (e *Executor) watchTasks(calls ...taskfile.Call) error { for i, c := range calls { tasks[i] = c.Task } - e.Logger.Errf("task: Started watching for tasks: %s", strings.Join(tasks, ", ")) + e.Logger.Errf(logger.Green, "task: Started watching for tasks: %s", strings.Join(tasks, ", ")) ctx, cancel := context.WithCancel(context.Background()) for _, c := range calls { c := c go func() { if err := e.RunTask(ctx, c); err != nil && !isContextError(err) { - e.Logger.Errf("%v", err) + e.Logger.Errf(logger.Red, "%v", err) } }() } @@ -49,7 +50,7 @@ func (e *Executor) watchTasks(calls ...taskfile.Call) error { for { select { case event := <-w.Event: - e.Logger.VerboseErrf("task: received watch event: %v", event) + e.Logger.VerboseErrf(logger.Magenta, "task: received watch event: %v", event) cancel() ctx, cancel = context.WithCancel(context.Background()) @@ -57,7 +58,7 @@ func (e *Executor) watchTasks(calls ...taskfile.Call) error { c := c go func() { if err := e.RunTask(ctx, c); err != nil && !isContextError(err) { - e.Logger.Errf("%v", err) + e.Logger.Errf(logger.Red, "%v", err) } }() } @@ -68,7 +69,7 @@ func (e *Executor) watchTasks(calls ...taskfile.Call) error { w.TriggerEvent(watcher.Remove, nil) }() default: - e.Logger.Errf("%v", err) + e.Logger.Errf(logger.Red, "%v", err) } case <-w.Closed: cancel() @@ -81,7 +82,7 @@ func (e *Executor) watchTasks(calls ...taskfile.Call) error { // re-register each second because we can have new files for { if err := e.registerWatchedFiles(w, calls...); err != nil { - e.Logger.Errf("%v", err) + e.Logger.Errf(logger.Red, "%v", err) } time.Sleep(time.Second) } From dd9cdb0ec9b9d6938b4a8cf214692daa134b13b9 Mon Sep 17 00:00:00 2001 From: Andrey Nering Date: Sat, 15 Jun 2019 22:47:15 -0300 Subject: [PATCH 2/4] Fix build after merging master --- precondition.go | 3 ++- status.go | 5 +++-- task.go | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/precondition.go b/precondition.go index eff123a0..ae41d15c 100644 --- a/precondition.go +++ b/precondition.go @@ -5,6 +5,7 @@ import ( "errors" "github.com/go-task/task/v2/internal/execext" + "github.com/go-task/task/v2/internal/logger" "github.com/go-task/task/v2/internal/taskfile" ) @@ -22,7 +23,7 @@ func (e *Executor) areTaskPreconditionsMet(ctx context.Context, t *taskfile.Task }) if err != nil { - e.Logger.Errf("task: %s", p.Msg) + e.Logger.Errf(logger.Magenta, "task: %s", p.Msg) return false, ErrPreconditionFailed } } diff --git a/status.go b/status.go index 7ebb5f84..9790578e 100644 --- a/status.go +++ b/status.go @@ -5,6 +5,7 @@ import ( "fmt" "github.com/go-task/task/v2/internal/execext" + "github.com/go-task/task/v2/internal/logger" "github.com/go-task/task/v2/internal/status" "github.com/go-task/task/v2/internal/taskfile" ) @@ -78,10 +79,10 @@ func (e *Executor) isTaskUpToDateStatus(ctx context.Context, t *taskfile.Task) ( Env: getEnviron(t), }) if err != nil { - e.Logger.VerboseOutf("task: status command %s exited non-zero: %s", s, err) + e.Logger.VerboseOutf(logger.Yellow, "task: status command %s exited non-zero: %s", s, err) return false, nil } - e.Logger.VerboseOutf("task: status command %s exited zero", s) + e.Logger.VerboseOutf(logger.Yellow, "task: status command %s exited zero", s) } return true, nil } diff --git a/task.go b/task.go index f7b4e1c3..56119a1c 100644 --- a/task.go +++ b/task.go @@ -229,7 +229,7 @@ func (e *Executor) RunTask(ctx context.Context, call taskfile.Call) error { } if err := e.mkdir(t); err != nil { - e.Logger.Errf("task: cannot make directory %q: %v", t.Dir, err) + e.Logger.Errf(logger.Red, "task: cannot make directory %q: %v", t.Dir, err) } for i := range t.Cmds { From 0e575e9c25b8c4df7bf8fce277ca78b7f964370a Mon Sep 17 00:00:00 2001 From: Andrey Nering Date: Sun, 7 Jul 2019 14:13:53 -0300 Subject: [PATCH 3/4] Add --color=false flag to disable colored output --- cmd/task/task.go | 3 +++ internal/logger/logger.go | 7 +++++++ task.go | 2 ++ 3 files changed, 12 insertions(+) diff --git a/cmd/task/task.go b/cmd/task/task.go index e93727f6..72f73bd8 100644 --- a/cmd/task/task.go +++ b/cmd/task/task.go @@ -60,6 +60,7 @@ func main() { summary bool dir string output string + color bool ) pflag.BoolVar(&versionFlag, "version", false, "show Task version") @@ -74,6 +75,7 @@ func main() { pflag.BoolVar(&summary, "summary", false, "show summary about a task") pflag.StringVarP(&dir, "dir", "d", "", "sets directory of execution") pflag.StringVarP(&output, "output", "o", "", "sets output style: [interleaved|group|prefixed]") + pflag.BoolVarP(&color, "color", "c", true, "colored output") pflag.Parse() if versionFlag { @@ -100,6 +102,7 @@ func main() { Dir: dir, Dry: dry, Summary: summary, + Color: color, Stdin: os.Stdin, Stdout: os.Stdout, diff --git a/internal/logger/logger.go b/internal/logger/logger.go index 17487b24..9a573106 100644 --- a/internal/logger/logger.go +++ b/internal/logger/logger.go @@ -25,6 +25,7 @@ type Logger struct { Stdout io.Writer Stderr io.Writer Verbose bool + Color bool } // Outf prints stuff to STDOUT. @@ -32,6 +33,9 @@ func (l *Logger) Outf(print PrintFunc, s string, args ...interface{}) { if len(args) == 0 { s, args = "%s", []interface{}{s} } + if !l.Color { + print = Default + } print(l.Stdout, s+"\n", args...) } @@ -47,6 +51,9 @@ func (l *Logger) Errf(print PrintFunc, s string, args ...interface{}) { if len(args) == 0 { s, args = "%s", []interface{}{s} } + if !l.Color { + print = Default + } print(l.Stderr, s+"\n", args...) } diff --git a/task.go b/task.go index 56119a1c..c5a33009 100644 --- a/task.go +++ b/task.go @@ -39,6 +39,7 @@ type Executor struct { Silent bool Dry bool Summary bool + Color bool Stdin io.Reader Stdout io.Writer @@ -108,6 +109,7 @@ func (e *Executor) Setup() error { Stdout: e.Stdout, Stderr: e.Stderr, Verbose: e.Verbose, + Color: e.Color, } v, err := strconv.ParseFloat(e.Taskfile.Version, 64) From 623db0ed94404840564ff4988f3d3a5892e608f8 Mon Sep 17 00:00:00 2001 From: Andrey Nering Date: Sun, 7 Jul 2019 14:18:02 -0300 Subject: [PATCH 4/4] Only have colored output on v3 --- Taskfile.yml | 2 +- docs/Taskfile.yml | 2 +- task.go | 9 +++++++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/Taskfile.yml b/Taskfile.yml index c85fd0ff..52393d09 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -1,4 +1,4 @@ -version: '2' +version: '3' includes: docs: ./docs diff --git a/docs/Taskfile.yml b/docs/Taskfile.yml index e3fe3ef8..d7360131 100644 --- a/docs/Taskfile.yml +++ b/docs/Taskfile.yml @@ -1,4 +1,4 @@ -version: '2' +version: '3' tasks: install: diff --git a/task.go b/task.go index c5a33009..72e3e0b5 100644 --- a/task.go +++ b/task.go @@ -124,8 +124,13 @@ func (e *Executor) Setup() error { if v < 1 { return fmt.Errorf(`task: Taskfile version should be greater or equal to v1`) } - if v > 2.6 { - return fmt.Errorf(`task: Taskfile versions greater than v2.6 not implemented in the version of Task`) + if v > 3.0 { + return fmt.Errorf(`task: Taskfile versions greater than v3.0 not implemented in the version of Task`) + } + + // Color available only on v3 + if v < 3 { + e.Logger.Color = false } if v < 2 {