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

View File

@ -9,8 +9,9 @@ func TestMetaColorize(t *testing.T) {
var m *Meta
var args, args2 []string
// Test basic, no change
// Test basic, color
m = new(Meta)
m.Color = true
args = []string{"foo", "bar"}
args2 = []string{"foo", "bar"}
args = m.process(args)
@ -21,6 +22,18 @@ func TestMetaColorize(t *testing.T) {
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
m = new(Meta)
args = []string{"foo", "-no-color", "bar"}