Add a --no-color flag to remove color codes from output
diff --git a/cmd/msg.go b/cmd/msg.go index 56b6942..d2f6787 100644 --- a/cmd/msg.go +++ b/cmd/msg.go
@@ -25,6 +25,9 @@ // The following will print the string "Foo" in yellow: // fmt.Print(Color(Yellow, "Foo")) func Color(code, msg string) string { + if NoColor { + return msg + } return fmt.Sprintf("\033[%sm%s\033[m", code, msg) }
diff --git a/cmd/util.go b/cmd/util.go index 5527153..9bc1c96 100644 --- a/cmd/util.go +++ b/cmd/util.go
@@ -16,6 +16,7 @@ // Quiet, when set to true, can suppress Info and Debug messages. var Quiet = false var IsDebugging = false +var NoColor = false // BeQuiet supresses Info and Debug messages. func BeQuiet(c cookoo.Context, p *cookoo.Params) (interface{}, cookoo.Interrupt) { @@ -24,6 +25,13 @@ return Quiet, nil } +// CheckColor turns off the colored output (and uses plain text output) for +// logging depending on the value of the "no-color" flag. +func CheckColor(c cookoo.Context, p *cookoo.Params) (interface{}, cookoo.Interrupt) { + NoColor = p.Get("no-color", false).(bool) + return NoColor, nil +} + // ReadyToGlide fails if the environment is not sufficient for using glide. // // Most importantly, it fails if glide.yaml is not present in the current
diff --git a/glide.go b/glide.go index e1456a0..89be05c 100644 --- a/glide.go +++ b/glide.go
@@ -94,6 +94,10 @@ Name: "debug", Usage: "Print Debug messages (verbose)", }, + cli.BoolFlag{ + Name: "no-color", + Usage: "Turn off colored output for log messages", + }, } app.CommandNotFound = func(c *cli.Context, command string) { cxt.Put("os.Args", os.Args) @@ -419,6 +423,7 @@ func setupHandler(c *cli.Context, route string, cxt cookoo.Context, router *cookoo.Router) { cxt.Put("q", c.GlobalBool("quiet")) cxt.Put("debug", c.GlobalBool("debug")) + cxt.Put("no-color", c.GlobalBool("no-color")) cxt.Put("yaml", c.GlobalString("yaml")) cxt.Put("cliArgs", c.Args()) if err := router.HandleRequest(route, cxt, false); err != nil { @@ -433,6 +438,8 @@ Does(cmd.BeQuiet, "quiet"). Using("quiet").From("cxt:q"). Using("debug").From("cxt:debug"). + Does(cmd.CheckColor, "no-color"). + Using("no-color").From("cxt:no-color"). Does(cmd.VersionGuard, "v") reg.Route("@ready", "Prepare for glide commands.").