Skip to content

Commit 8536c9d

Browse files
committed
Turn on SilenceErrors and SilenceUsage to prevent Cobra from messing up the stderr output
Signed-off-by: Richard Wall <[email protected]>
1 parent 23d704a commit 8536c9d

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

cmd/root.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import (
88
"github.com/jetstack/preflight/pkg/logs"
99
"github.com/spf13/cobra"
1010
"github.com/spf13/pflag"
11+
12+
"github.com/jetstack/preflight/pkg/logs"
1113
)
1214

1315
// rootCmd represents the base command when called without any subcommands
@@ -21,6 +23,14 @@ Preflight checks are bundled into Packages`,
2123
PersistentPreRun: func(cmd *cobra.Command, args []string) {
2224
logs.Initialize()
2325
},
26+
// SilenceErrors and SilenceUsage prevents this command or any sub-command
27+
// from printing arbitrary text to stderr.
28+
// Why? To ensure that each line of output can be parsed as a single message
29+
// for consumption by logging agents such as fluentd.
30+
// Usage information is still available on stdout with the `-h` and `--help`
31+
// flags.
32+
SilenceErrors: true,
33+
SilenceUsage: true,
2434
}
2535

2636
func init() {

0 commit comments

Comments
 (0)