Fix a bug where yaml output was broken in sensuctl dump
@@ -172,7 +172,7 @@ func execute(cli *cli.SensuCli) func(*cobra.Command, []string) error {
w = f
}
- for _, req := range requests {
+ for i, req := range requests {
// set the namespaces on the requests
ok, err := cmd.Flags().GetBool(flags.AllNamespaces)
if err != nil {
@@ -204,6 +204,10 @@ func execute(cli *cli.SensuCli) func(*cobra.Command, []string) error {
}
val = reflect.Indirect(val)
+ if val.Len() == 0 {
+ continue
+ }
+
resources := make([]corev2.Resource, val.Len())
for i := range resources {
resources[i] = val.Index(i).Interface().(corev2.Resource)
@@ -215,6 +219,9 @@ func execute(cli *cli.SensuCli) func(*cobra.Command, []string) error {
case config.FormatWrappedJSON:
err = helpers.PrintWrappedJSONList(resources, w)
case config.FormatYAML:
+ if i > 0 {
+ _, _ = fmt.Fprintln(cmd.OutOrStdout(), "---")
+ }
err = helpers.PrintYAML(resources, w)
default:
err = fmt.Errorf("invalid output format: %s", format)
