Skip to content

Commit 09a4f55

Browse files
committed
add colors flag
1 parent e83dcd9 commit 09a4f55

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+81
-61
lines changed

tfexec/apply.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ func (tf *Terraform) applyCmd(ctx context.Context, opts ...ApplyOption) (*exec.C
106106
o.configureApply(&c)
107107
}
108108

109-
args := []string{"apply", "-no-color", "-auto-approve", "-input=false"}
109+
args := []string{"apply", "-auto-approve", "-input=false"}
110110

111111
// string opts: only pass if set
112112
if c.backup != "" {

tfexec/apply_test.go

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

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

tfexec/cmd.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,11 @@ func (tf *Terraform) buildEnv(mergeEnv map[string]string) []string {
180180
}
181181

182182
func (tf *Terraform) buildTerraformCmd(ctx context.Context, mergeEnv map[string]string, args ...string) *exec.Cmd {
183-
cmd := exec.CommandContext(ctx, tf.execPath, args...)
183+
if !tf.colors {
184+
args = append(args, "-no-color")
185+
}
186+
187+
cmd := exec.Command(tf.execPath, args...)
184188

185189
cmd.Env = tf.buildEnv(mergeEnv)
186190
cmd.Dir = tf.workingDir

tfexec/destroy.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ func (tf *Terraform) destroyCmd(ctx context.Context, opts ...DestroyOption) (*ex
102102
o.configureDestroy(&c)
103103
}
104104

105-
args := []string{"destroy", "-no-color", "-auto-approve", "-input=false"}
105+
args := []string{"destroy", "-auto-approve", "-input=false"}
106106

107107
// string opts: only pass if set
108108
if c.backup != "" {

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",
3029
"-auto-approve",
3130
"-input=false",
3231
"-lock-timeout=0s",
3332
"-lock=true",
3433
"-parallelism=10",
3534
"-refresh=true",
35+
"-no-color",
3636
}, nil, destroyCmd)
3737
})
3838

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

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

tfexec/fmt.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ func (tf *Terraform) formatCmd(ctx context.Context, args []string, opts ...Forma
145145
o.configureFormat(&c)
146146
}
147147

148-
args = append([]string{"fmt", "-no-color"}, args...)
148+
args = append([]string{"fmt"}, args...)
149149

150150
if c.recursive {
151151
args = append(args, "-recursive")

tfexec/get.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func (tf *Terraform) getCmd(ctx context.Context, opts ...GetCmdOption) (*exec.Cm
4040
o.configureGet(&c)
4141
}
4242

43-
args := []string{"get", "-no-color"}
43+
args := []string{"get"}
4444

4545
args = append(args, "-update="+fmt.Sprint(c.update))
4646

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-
"-no-color",
3029
"-update=false",
30+
"-no-color",
3131
}, nil, getCmd)
3232
})
3333
}

tfexec/graph_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ func TestGraphCmd_v013(t *testing.T) {
2828

2929
assertCmd(t, []string{
3030
"graph",
31+
"-no-color",
3132
}, nil, graphCmd)
3233
})
3334

@@ -42,6 +43,7 @@ func TestGraphCmd_v013(t *testing.T) {
4243
"teststate",
4344
"-draw-cycles",
4445
"-type=output",
46+
"-no-color",
4547
}, nil, graphCmd)
4648
})
4749
}
@@ -62,6 +64,7 @@ func TestGraphCmd_v1(t *testing.T) {
6264

6365
assertCmd(t, []string{
6466
"graph",
67+
"-no-color",
6568
}, nil, graphCmd)
6669
})
6770

@@ -76,6 +79,7 @@ func TestGraphCmd_v1(t *testing.T) {
7679
"-plan=teststate",
7780
"-draw-cycles",
7881
"-type=output",
82+
"-no-color",
7983
}, nil, graphCmd)
8084
})
8185
}

tfexec/import.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func (tf *Terraform) importCmd(ctx context.Context, address, id string, opts ...
8888
o.configureImport(&c)
8989
}
9090

91-
args := []string{"import", "-no-color", "-input=false"}
91+
args := []string{"import", "-input=false"}
9292

9393
// string opts: only pass if set
9494
if c.backup != "" {

0 commit comments

Comments
 (0)