diff options
Diffstat (limited to 'client/go/cmd/root.go')
-rw-r--r-- | client/go/cmd/root.go | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/client/go/cmd/root.go b/client/go/cmd/root.go index cd8427c3ac6..7fe704e4918 100644 --- a/client/go/cmd/root.go +++ b/client/go/cmd/root.go @@ -6,6 +6,7 @@ package cmd import ( "fmt" + "io/ioutil" "log" "os" @@ -36,6 +37,7 @@ Vespa documentation: https://docs.vespa.ai`, applicationArg string waitSecsArg int colorArg string + quietArg bool color = aurora.NewAurora(false) stdout = colorable.NewColorableStdout() @@ -47,17 +49,23 @@ const ( targetFlag = "target" waitFlag = "wait" colorFlag = "color" + quietFlag = "quiet" ) func isTerminal() bool { - file, ok := stdout.(*os.File) - if ok { - return isatty.IsTerminal(file.Fd()) + if f, ok := stdout.(*os.File); ok { + return isatty.IsTerminal(f.Fd()) + } + if f, ok := stderr.(*os.File); ok { + return isatty.IsTerminal(f.Fd()) } return false } func configureOutput() { + if quietArg { + stdout = ioutil.Discard + } log.SetFlags(0) // No timestamps log.SetOutput(stdout) @@ -88,10 +96,12 @@ func init() { rootCmd.PersistentFlags().StringVarP(&applicationArg, applicationFlag, "a", "", "The application to manage") rootCmd.PersistentFlags().IntVarP(&waitSecsArg, waitFlag, "w", 0, "Number of seconds to wait for a service to become ready") rootCmd.PersistentFlags().StringVarP(&colorArg, colorFlag, "c", "auto", "Whether to use colors in output. Can be \"auto\", \"never\" or \"always\"") + rootCmd.PersistentFlags().BoolVarP(&quietArg, quietFlag, "q", false, "Quiet mode. Only errors are printed.") bindFlagToConfig(targetFlag, rootCmd) bindFlagToConfig(applicationFlag, rootCmd) bindFlagToConfig(waitFlag, rootCmd) bindFlagToConfig(colorFlag, rootCmd) + bindFlagToConfig(quietFlag, rootCmd) } // Execute executes the root command. |