Skip to content

Commit 817f07c

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 f6b3b4b commit 817f07c

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
@@ -7,6 +7,8 @@ import (
77

88
"github.com/spf13/cobra"
99
"github.com/spf13/pflag"
10+
11+
"github.com/jetstack/preflight/pkg/logs"
1012
)
1113

1214
// rootCmd represents the base command when called without any subcommands
@@ -17,6 +19,14 @@ var rootCmd = &cobra.Command{
1719
configuration checks using Open Policy Agent (OPA).
1820
1921
Preflight checks are bundled into Packages`,
22+
// SilenceErrors and SilenceUsage prevents this command or any sub-command
23+
// from printing arbitrary text to stderr.
24+
// Why? To ensure that each line of output can be parsed as a single message
25+
// for consumption by logging agents such as fluentd.
26+
// Usage information is still available on stdout with the `-h` and `--help`
27+
// flags.
28+
SilenceErrors: true,
29+
SilenceUsage: true,
2030
}
2131

2232
func init() {

0 commit comments

Comments
 (0)