Skip to content

Commit 28892fd

Browse files
committed
fix(cmdx): use better yaml library
1 parent 5be2287 commit 28892fd

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

cmdx/printing.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ func PrintJSONAble(cmd *cobra.Command, d interface{ String() string }) {
153153
if i, ok := d.(interfacer); ok {
154154
v = i
155155
}
156-
printJSON(cmd.OutOrStdout(), v, true)
156+
printYAML(cmd.OutOrStdout(), v)
157157
}
158158
}
159159

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

204204
func printYAML(w io.Writer, v interface{}) {
205-
e, err := yaml.Marshal(v)
205+
j, err := json.Marshal(v)
206+
Must(err, "Error encoding JSON: %s", err)
207+
e, err := yaml.JSONToYAML(j)
206208
Must(err, "Error encoding YAML: %s", err)
207209
_, _ = w.Write(e)
208210
}

cmdx/printing_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ func TestPrinting(t *testing.T) {
263263
},
264264
{
265265
fArgs: []string{"--" + FlagFormat, string(FormatYAML)},
266-
expected: "[]",
266+
expected: "null",
267267
},
268268
} {
269269
t.Run(fmt.Sprintf("format=%v", tc.fArgs), func(t *testing.T) {

0 commit comments

Comments
 (0)