Merge branch 'albrow-feature/no-color' Conflicts: glide.go
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 d4fd8ba..3a27e63 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 59b1c82..9e7ad57 100644 --- a/glide.go +++ b/glide.go
@@ -103,6 +103,10 @@ Usage: "The location of Glide files", EnvVar: "GLIDE_HOME", }, + 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) @@ -458,6 +462,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("home", c.GlobalString("home")) cxt.Put("cliArgs", c.Args()) @@ -473,6 +478,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.").