From 541d23eea059d974f3010796bc3dd9dfcd930699 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 17 Jul 2014 09:34:32 -0700 Subject: [PATCH] command: can set Color to false explicitly --- command/meta.go | 5 +++-- command/meta_test.go | 15 ++++++++++++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/command/meta.go b/command/meta.go index d8ee72293..b0ce5ad7d 100644 --- a/command/meta.go +++ b/command/meta.go @@ -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 diff --git a/command/meta_test.go b/command/meta_test.go index 6a2f680f3..0b46ebaea 100644 --- a/command/meta_test.go +++ b/command/meta_test.go @@ -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"}