Skip to content

Commit 3d5d15e

Browse files
committed
add changelog entry
1 parent 09a4f55 commit 3d5d15e

25 files changed

+165
-128
lines changed

CHANGELOG.md

Lines changed: 85 additions & 85 deletions
Large diffs are not rendered by default.

tfexec/apply_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ func TestApplyCmd(t *testing.T) {
4343

4444
assertCmd(t, []string{
4545
"apply",
46+
"-no-color",
4647
"-auto-approve",
4748
"-input=false",
4849
"-backup=testbackup",
@@ -61,7 +62,6 @@ func TestApplyCmd(t *testing.T) {
6162
"-var", "var1=foo",
6263
"-var", "var2=bar",
6364
"testfile",
64-
"-no-color",
6565
}, nil, applyCmd)
6666
})
6767
}

tfexec/cmd.go

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,10 +181,10 @@ func (tf *Terraform) buildEnv(mergeEnv map[string]string) []string {
181181

182182
func (tf *Terraform) buildTerraformCmd(ctx context.Context, mergeEnv map[string]string, args ...string) *exec.Cmd {
183183
if !tf.colors {
184-
args = append(args, "-no-color")
184+
args = addColorFlag(args)
185185
}
186186

187-
cmd := exec.Command(tf.execPath, args...)
187+
cmd := exec.CommandContext(ctx, tf.execPath, args...)
188188

189189
cmd.Env = tf.buildEnv(mergeEnv)
190190
cmd.Dir = tf.workingDir
@@ -194,6 +194,36 @@ func (tf *Terraform) buildTerraformCmd(ctx context.Context, mergeEnv map[string]
194194
return cmd
195195
}
196196

197+
func addColorFlag(args []string) []string {
198+
found := false
199+
insertIndex := 0
200+
for i, a := range args {
201+
if strings.HasPrefix(a, "-") && insertIndex == 0 {
202+
insertIndex = i
203+
}
204+
205+
if a == "-no-color" {
206+
found = true
207+
}
208+
}
209+
if insertIndex == 0 {
210+
insertIndex = len(args)
211+
}
212+
if !found {
213+
args = insert(args, insertIndex, "-no-color")
214+
}
215+
return args
216+
}
217+
218+
func insert(a []string, index int, value string) []string {
219+
if len(a) == index {
220+
return append(a, value)
221+
}
222+
a = append(a[:index+1], a[index:]...)
223+
a[index] = value
224+
return a
225+
}
226+
197227
func (tf *Terraform) runTerraformCmdJSON(ctx context.Context, cmd *exec.Cmd, v interface{}) error {
198228
var outbuf = bytes.Buffer{}
199229
cmd.Stdout = mergeWriters(cmd.Stdout, &outbuf)

tfexec/destroy_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ func TestDestroyCmd(t *testing.T) {
2626

2727
assertCmd(t, []string{
2828
"destroy",
29+
"-no-color",
2930
"-auto-approve",
3031
"-input=false",
3132
"-lock-timeout=0s",
3233
"-lock=true",
3334
"-parallelism=10",
3435
"-refresh=true",
35-
"-no-color",
3636
}, nil, destroyCmd)
3737
})
3838

@@ -44,6 +44,7 @@ func TestDestroyCmd(t *testing.T) {
4444

4545
assertCmd(t, []string{
4646
"destroy",
47+
"-no-color",
4748
"-auto-approve",
4849
"-input=false",
4950
"-backup=testbackup",
@@ -59,7 +60,6 @@ func TestDestroyCmd(t *testing.T) {
5960
"-var", "var1=foo",
6061
"-var", "var2=bar",
6162
"destroydir",
62-
"-no-color",
6363
}, nil, destroyCmd)
6464
})
6565
}

tfexec/get_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ func TestGetCmd(t *testing.T) {
2626

2727
assertCmd(t, []string{
2828
"get",
29-
"-update=false",
3029
"-no-color",
30+
"-update=false",
3131
}, nil, getCmd)
3232
})
3333
}

tfexec/graph_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ func TestGraphCmd_v013(t *testing.T) {
4141
assertCmd(t, []string{
4242
"graph",
4343
"teststate",
44+
"-no-color",
4445
"-draw-cycles",
4546
"-type=output",
46-
"-no-color",
4747
}, nil, graphCmd)
4848
})
4949
}
@@ -76,10 +76,10 @@ func TestGraphCmd_v1(t *testing.T) {
7676

7777
assertCmd(t, []string{
7878
"graph",
79+
"-no-color",
7980
"-plan=teststate",
8081
"-draw-cycles",
8182
"-type=output",
82-
"-no-color",
8383
}, nil, graphCmd)
8484
})
8585
}

tfexec/import_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ func TestImportCmd(t *testing.T) {
2626

2727
assertCmd(t, []string{
2828
"import",
29+
"-no-color",
2930
"-input=false",
3031
"-lock-timeout=0s",
3132
"-lock=true",
3233
"my-addr",
3334
"my-id",
34-
"-no-color",
3535
}, nil, importCmd)
3636
})
3737

@@ -53,6 +53,7 @@ func TestImportCmd(t *testing.T) {
5353

5454
assertCmd(t, []string{
5555
"import",
56+
"-no-color",
5657
"-input=false",
5758
"-backup=testbackup",
5859
"-lock-timeout=200s",
@@ -65,7 +66,6 @@ func TestImportCmd(t *testing.T) {
6566
"-var", "var2=bar",
6667
"my-addr2",
6768
"my-id2",
68-
"-no-color",
6969
}, nil, importCmd)
7070
})
7171
}

tfexec/init_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ func TestInitCmd_v012(t *testing.T) {
3232

3333
assertCmd(t, []string{
3434
"init",
35+
"-no-color",
3536
"-force-copy",
3637
"-input=false",
3738
"-lock-timeout=0s",
@@ -41,7 +42,6 @@ func TestInitCmd_v012(t *testing.T) {
4142
"-lock=true",
4243
"-get-plugins=true",
4344
"-verify-plugins=true",
44-
"-no-color",
4545
}, nil, initCmd)
4646
})
4747

@@ -53,6 +53,7 @@ func TestInitCmd_v012(t *testing.T) {
5353

5454
assertCmd(t, []string{
5555
"init",
56+
"-no-color",
5657
"-force-copy",
5758
"-input=false",
5859
"-from-module=testsource",
@@ -70,7 +71,6 @@ func TestInitCmd_v012(t *testing.T) {
7071
"-plugin-dir=testdir1",
7172
"-plugin-dir=testdir2",
7273
"initdir",
73-
"-no-color",
7474
}, nil, initCmd)
7575
})
7676
}

tfexec/output_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ func TestOutputCmd(t *testing.T) {
2323

2424
assertCmd(t, []string{
2525
"output",
26-
"-json",
2726
"-no-color",
27+
"-json",
2828
}, nil, outputCmd)
2929
})
3030

@@ -34,9 +34,9 @@ func TestOutputCmd(t *testing.T) {
3434

3535
assertCmd(t, []string{
3636
"output",
37+
"-no-color",
3738
"-json",
3839
"-state=teststate",
39-
"-no-color",
4040
}, nil, outputCmd)
4141
})
4242
}

tfexec/plan_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ func TestPlanCmd(t *testing.T) {
2626

2727
assertCmd(t, []string{
2828
"plan",
29+
"-no-color",
2930
"-input=false",
3031
"-detailed-exitcode",
3132
"-lock-timeout=0s",
3233
"-lock=true",
3334
"-parallelism=10",
3435
"-refresh=true",
35-
"-no-color",
3636
}, nil, planCmd)
3737
})
3838

@@ -59,6 +59,7 @@ func TestPlanCmd(t *testing.T) {
5959

6060
assertCmd(t, []string{
6161
"plan",
62+
"-no-color",
6263
"-input=false",
6364
"-detailed-exitcode",
6465
"-lock-timeout=22s",
@@ -76,7 +77,6 @@ func TestPlanCmd(t *testing.T) {
7677
"-var", "android=paranoid",
7778
"-var", "brain_size=planet",
7879
"earth",
79-
"-no-color",
8080
}, nil, planCmd)
8181
})
8282
}

tfexec/providers_lock_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ func TestProvidersLockCmd(t *testing.T) {
3434
assertCmd(t, []string{
3535
"providers",
3636
"lock",
37+
"-no-color",
3738
"-fs-mirror=test",
3839
"-net-mirror=test",
3940
"-platform=linux_amd64",
4041
"workingdir",
41-
"-no-color",
4242
}, nil, lockCmd)
4343
})
4444
}

tfexec/providers_schema_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func TestProvidersSchemaCmd(t *testing.T) {
2323
assertCmd(t, []string{
2424
"providers",
2525
"schema",
26-
"-json",
2726
"-no-color",
27+
"-json",
2828
}, nil, schemaCmd)
2929
}

tfexec/refresh_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ func TestRefreshCmd(t *testing.T) {
2626

2727
assertCmd(t, []string{
2828
"refresh",
29+
"-no-color",
2930
"-input=false",
3031
"-lock-timeout=0s",
3132
"-lock=true",
32-
"-no-color",
3333
}, nil, refreshCmd)
3434
})
3535

@@ -41,6 +41,7 @@ func TestRefreshCmd(t *testing.T) {
4141

4242
assertCmd(t, []string{
4343
"refresh",
44+
"-no-color",
4445
"-input=false",
4546
"-backup=testbackup",
4647
"-lock-timeout=200s",
@@ -53,7 +54,6 @@ func TestRefreshCmd(t *testing.T) {
5354
"-var", "var1=foo",
5455
"-var", "var2=bar",
5556
"refreshdir",
56-
"-no-color",
5757
}, nil, refreshCmd)
5858
})
5959
}

tfexec/show_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ func TestShowCmd(t *testing.T) {
2323

2424
assertCmd(t, []string{
2525
"show",
26-
"-json",
2726
"-no-color",
27+
"-json",
2828
}, nil, showCmd)
2929
}
3030

@@ -43,9 +43,9 @@ func TestShowStateFileCmd(t *testing.T) {
4343

4444
assertCmd(t, []string{
4545
"show",
46+
"-no-color",
4647
"-json",
4748
"statefilepath",
48-
"-no-color",
4949
}, nil, showCmd)
5050
}
5151

@@ -64,9 +64,9 @@ func TestShowPlanFileCmd(t *testing.T) {
6464

6565
assertCmd(t, []string{
6666
"show",
67+
"-no-color",
6768
"-json",
6869
"planfilepath",
69-
"-no-color",
7070
}, nil, showCmd)
7171
}
7272

tfexec/state_mv_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ func TestStateMvCmd(t *testing.T) {
2727
assertCmd(t, []string{
2828
"state",
2929
"mv",
30+
"-no-color",
3031
"-lock-timeout=0s",
3132
"-lock=true",
3233
"testsource",
3334
"testdestination",
34-
"-no-color",
3535
}, nil, stateMvCmd)
3636
})
3737

@@ -44,6 +44,7 @@ func TestStateMvCmd(t *testing.T) {
4444
assertCmd(t, []string{
4545
"state",
4646
"mv",
47+
"-no-color",
4748
"-backup=testbackup",
4849
"-backup-out=testbackupout",
4950
"-lock-timeout=200s",
@@ -52,7 +53,6 @@ func TestStateMvCmd(t *testing.T) {
5253
"-lock=false",
5354
"testsrc",
5455
"testdest",
55-
"-no-color",
5656
}, nil, stateMvCmd)
5757
})
5858
}

tfexec/state_pull_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ func TestStatePull(t *testing.T) {
2121
assertCmd(t, []string{
2222
"state",
2323
"pull",
24+
"-no-color",
2425
}, nil, statePullCmd)
2526
})
2627
}

tfexec/state_push_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ func TestStatePushCmd(t *testing.T) {
2424
assertCmd(t, []string{
2525
"state",
2626
"push",
27+
"-no-color",
2728
"-lock=false",
2829
"-lock-timeout=0s",
2930
"testpath",
@@ -39,6 +40,7 @@ func TestStatePushCmd(t *testing.T) {
3940
assertCmd(t, []string{
4041
"state",
4142
"push",
43+
"-no-color",
4244
"-force",
4345
"-lock=true",
4446
"-lock-timeout=10s",

0 commit comments

Comments
 (0)