Skip to content

Commit d2c82ba

Browse files
committed
Add switching logic for printers in different formats
The data is printed to c.Out which is os.Stdout in most cases. Signed-off-by: Nabarun Pal <[email protected]>
1 parent 354878b commit d2c82ba

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

pkg/kepctl/query.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,18 @@ func (c *Client) Query(opts QueryOpts) error {
118118
keep = append(keep, k)
119119
}
120120

121-
c.PrintTable(DefaultPrintConfigs("LastUpdated", "Stage", "Status", "SIG", "Authors", "Title", "Link"), keep)
121+
switch opts.Output {
122+
case "table":
123+
c.PrintTable(DefaultPrintConfigs("LastUpdated", "Stage", "Status", "SIG", "Authors", "Title", "Link"), keep)
124+
case "yaml":
125+
c.PrintYAML(keep)
126+
case "json":
127+
c.PrintJSON(keep)
128+
default:
129+
// this check happens as a validation step in cobra as well
130+
// added it for additional verbosity
131+
return fmt.Errorf("unsupported output format: %s. Valid values: %s", opts.Output, SupportedOutputOpts)
132+
}
122133
return nil
123134
}
124135

0 commit comments

Comments
 (0)