Fix error when TF_CLI_ARGS adds -no-color argument

Fixes #25845
This commit is contained in:
Zachary Whaley 2020-08-13 13:10:09 -05:00
parent f5c8ef19ad
commit af8d5a69d8
2 changed files with 22 additions and 3 deletions

View File

@ -435,14 +435,18 @@ func (m *Meta) process(args []string) []string {
// Set colorization
m.color = m.Color
for i, v := range args {
i := 0 // output index
for _, v := range args {
if v == "-no-color" {
m.color = false
m.Color = false
args = append(args[:i], args[i+1:]...)
break
} else {
// copy and increment index
args[i] = v
i++
}
}
args = args[:i]
// Set the UI
m.oldUi = m.Ui

View File

@ -55,6 +55,21 @@ func TestMetaColorize(t *testing.T) {
if !m.Colorize().Disable {
t.Fatal("should be disabled")
}
// Test disable #2
// Verify multiple -no-color options are removed from args slice.
// E.g. an additional -no-color arg could be added by TF_CLI_ARGS.
m = new(Meta)
m.Color = true
args = []string{"foo", "-no-color", "bar", "-no-color"}
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")
}
}
func TestMetaInputMode(t *testing.T) {