diff --git a/command/format.go b/command/format.go index 630056d177..5db41c7e11 100644 --- a/command/format.go +++ b/command/format.go @@ -28,6 +28,13 @@ func OutputList(ui cli.Ui, format string, secret *api.Secret) int { } func outputWithFormat(ui cli.Ui, format string, secret *api.Secret, data interface{}) int { + // If we had a colored UI, pull out the nested ui so we don't add escape + // sequences for outputting json, etc. + colorUI, ok := ui.(*cli.ColoredUi) + if ok { + ui = colorUI.Ui + } + formatter, ok := Formatters[strings.ToLower(format)] if !ok { ui.Error(fmt.Sprintf("Invalid output format: %s", format)) diff --git a/command/format_test.go b/command/format_test.go index 8e32d2419c..44020a1aa6 100644 --- a/command/format_test.go +++ b/command/format_test.go @@ -24,18 +24,10 @@ func (m mockUi) AskSecret(_ string) (string, error) { m.t.FailNow() return "", nil } -func (m mockUi) Output(s string) { - output = s -} -func (m mockUi) Info(s string) { - m.t.Log(s) -} -func (m mockUi) Error(s string) { - m.t.Log(s) -} -func (m mockUi) Warn(s string) { - m.t.Log(s) -} +func (m mockUi) Output(s string) { output = s } +func (m mockUi) Info(s string) { m.t.Log(s) } +func (m mockUi) Error(s string) { m.t.Log(s) } +func (m mockUi) Warn(s string) { m.t.Log(s) } func TestJsonFormatter(t *testing.T) { ui := mockUi{t: t, SampleData: "something"}