Skip to content

Commit

Permalink
fix(cmdx): use better yaml library
Browse files Browse the repository at this point in the history
  • Loading branch information
aeneasr committed Mar 24, 2022
1 parent 5be2287 commit 28892fd
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions cmdx/printing.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func PrintJSONAble(cmd *cobra.Command, d interface{ String() string }) {
if i, ok := d.(interfacer); ok {
v = i
}
printJSON(cmd.OutOrStdout(), v, true)
printYAML(cmd.OutOrStdout(), v)
}
}

Expand Down Expand Up @@ -202,7 +202,9 @@ func printJSON(w io.Writer, v interface{}, pretty bool) {
}

func printYAML(w io.Writer, v interface{}) {
e, err := yaml.Marshal(v)
j, err := json.Marshal(v)
Must(err, "Error encoding JSON: %s", err)
e, err := yaml.JSONToYAML(j)
Must(err, "Error encoding YAML: %s", err)
_, _ = w.Write(e)
}
Expand Down
2 changes: 1 addition & 1 deletion cmdx/printing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ func TestPrinting(t *testing.T) {
},
{
fArgs: []string{"--" + FlagFormat, string(FormatYAML)},
expected: "[]",
expected: "null",
},
} {
t.Run(fmt.Sprintf("format=%v", tc.fArgs), func(t *testing.T) {
Expand Down

0 comments on commit 28892fd

Please sign in to comment.