command: can set Color to false explicitly

This commit is contained in:
Mitchell Hashimoto 2014-07-17 09:34:32 -07:00
parent d956880e2f
commit 541d23eea0
2 changed files with 17 additions and 3 deletions

View File

@ -16,6 +16,7 @@ type Meta struct {
ContextOpts *terraform.ContextOpts ContextOpts *terraform.ContextOpts
Ui cli.Ui Ui cli.Ui
color bool
oldUi cli.Ui oldUi cli.Ui
} }
@ -23,7 +24,7 @@ type Meta struct {
func (m *Meta) Colorize() *colorstring.Colorize { func (m *Meta) Colorize() *colorstring.Colorize {
return &colorstring.Colorize{ return &colorstring.Colorize{
Colors: colorstring.DefaultColors, Colors: colorstring.DefaultColors,
Disable: !m.Color, Disable: !m.color,
Reset: true, Reset: true,
} }
} }
@ -115,7 +116,7 @@ func (m *Meta) process(args []string) []string {
} }
// Set colorization // Set colorization
m.Color = true m.color = m.Color
for i, v := range args { for i, v := range args {
if v == "-no-color" { if v == "-no-color" {
m.Color = false m.Color = false

View File

@ -9,8 +9,9 @@ func TestMetaColorize(t *testing.T) {
var m *Meta var m *Meta
var args, args2 []string var args, args2 []string
// Test basic, no change // Test basic, color
m = new(Meta) m = new(Meta)
m.Color = true
args = []string{"foo", "bar"} args = []string{"foo", "bar"}
args2 = []string{"foo", "bar"} args2 = []string{"foo", "bar"}
args = m.process(args) args = m.process(args)
@ -21,6 +22,18 @@ func TestMetaColorize(t *testing.T) {
t.Fatal("should not be disabled") t.Fatal("should not be disabled")
} }
// Test basic, no change
m = new(Meta)
args = []string{"foo", "bar"}
args2 = []string{"foo", "bar"}
args = m.process(args)
if !reflect.DeepEqual(args, args2) {
t.Fatalf("bad: %#v", args)
}
if !m.Colorize().Disable {
t.Fatal("should be disabled")
}
// Test disable #1 // Test disable #1
m = new(Meta) m = new(Meta)
args = []string{"foo", "-no-color", "bar"} args = []string{"foo", "-no-color", "bar"}