Skip to content

Commit 354878b

Browse files
committed
Implement printers for json and yaml output formats
Signed-off-by: Nabarun Pal <[email protected]>
1 parent bd0beab commit 354878b

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

pkg/kepctl/kepctl.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package kepctl
1919
import (
2020
"bytes"
2121
"context"
22+
"encoding/json"
2223
"fmt"
2324
"io"
2425
"io/ioutil"
@@ -481,3 +482,25 @@ func (c *Client) PrintTable(configs []PrintConfig, proposals []*keps.Proposal) {
481482
}
482483
table.Render()
483484
}
485+
486+
// PrintYAML outputs keps array as YAML to c.Out
487+
func (c *Client) PrintYAML(proposals []*keps.Proposal) {
488+
data, err := yaml.Marshal(proposals)
489+
if err != nil {
490+
fmt.Fprintf(c.Err, "error printing keps as YAML: %s", err)
491+
return
492+
}
493+
494+
fmt.Fprintln(c.Out, string(data))
495+
}
496+
497+
// PrintJSON outputs keps array as YAML to c.Out
498+
func (c *Client) PrintJSON(proposals []*keps.Proposal) {
499+
data, err := json.Marshal(proposals)
500+
if err != nil {
501+
fmt.Fprintf(c.Err, "error printing keps as JSON: %s", err)
502+
return
503+
}
504+
505+
fmt.Fprintln(c.Out, string(data))
506+
}

0 commit comments

Comments
 (0)