Update format to not use colored UI for json/yaml

This commit is contained in:
Seth Vargo 2017-09-05 00:01:44 -04:00
parent 38823efa70
commit 9b949cebd5
No known key found for this signature in database
GPG Key ID: C921994F9C27E0FF
2 changed files with 11 additions and 12 deletions

View File

@ -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))

View File

@ -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"}