Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion ctl/dump/dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (

"github.com/spf13/cobra"
"google.golang.org/protobuf/encoding/protojson"
"sigs.k8s.io/yaml"

adminv2 "kmesh.net/kmesh/api/v2/admin"
"kmesh.net/kmesh/ctl/utils"
Expand Down Expand Up @@ -62,7 +63,7 @@ kmeshctl dump <kmesh-daemon-pod> kernel-native -o json`,
},
}

cmd.Flags().StringVarP(&outputFormat, "output", "o", "table", "Output format: table or json")
cmd.Flags().StringVarP(&outputFormat, "output", "o", "table", "Output format: table, json, or yaml")
return cmd
}

Expand Down Expand Up @@ -108,6 +109,17 @@ func RunDump(cmd *cobra.Command, args []string, outputFormat string) error {
return nil
}

if outputFormat == "yaml" {
yamlData, err := yaml.JSONToYAML(body)
if err != nil {
log.Errorf("failed to convert JSON to YAML: %v, falling back to raw output", err)
fmt.Println(string(body))
return nil
}
fmt.Println(string(yamlData))
return nil
}
Comment thread
Psykii22 marked this conversation as resolved.

switch mode {
case constants.KernelNativeMode:
printKernelNativeTable(body)
Expand Down
2 changes: 1 addition & 1 deletion docs/ctl/kmeshctl_dump.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ kmeshctl dump <kmesh-daemon-pod> kernel-native -o json

```bash
-h, --help help for dump
-o, --output string Output format: table or json (default "table")
-o, --output string Output format: table, json, or yaml (default "table")
```

### SEE ALSO
Expand Down
Loading