Skip to content

Commit 6090c9c

Browse files
committed
Add functionality to suppress log like when using structured outputs
This has to be done because printing debug/info events in the same stream as structured output like json or yaml would get incomprehendible to downstream consumers. Signed-off-by: Nabarun Pal <[email protected]>
1 parent d2c82ba commit 6090c9c

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

pkg/kepctl/query.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ var (
3636

3737
// DefaultOutputOpt is the default output format for kepctl query
3838
DefaultOutputOpt = "table"
39+
40+
StructuredOutputFormats = []string{
41+
"json",
42+
"yaml",
43+
}
3944
)
4045

4146
type QueryOpts struct {
@@ -73,7 +78,20 @@ func (c *QueryOpts) Validate(args []string) error {
7378
// Query searches the local repo and possibly GitHub for KEPs
7479
// that match the search criteria.
7580
func (c *Client) Query(opts QueryOpts) error {
76-
fmt.Fprintf(c.Out, "Searching for KEPs...\n")
81+
// if output format is json/yaml, suppress other outputs
82+
// json/yaml are structured formats, logging events which
83+
// do not conform to the spec will create formatting issues
84+
var suppressOutputs bool
85+
if sliceContains(StructuredOutputFormats, opts.Output) {
86+
suppressOutputs = true
87+
} else {
88+
suppressOutputs = false
89+
}
90+
91+
if !suppressOutputs {
92+
fmt.Fprintf(c.Out, "Searching for KEPs...\n")
93+
}
94+
7795
repoPath, err := c.findEnhancementsRepo(opts.CommonArgs)
7896
if err != nil {
7997
return errors.Wrap(err, "unable to search KEPs")

0 commit comments

Comments
 (0)