diff --git a/internal/cli/root.go b/internal/cli/root.go index b15b60a1..74c1481c 100644 --- a/internal/cli/root.go +++ b/internal/cli/root.go @@ -63,15 +63,17 @@ func NewRootCommand(s state.State) *cobra.Command { ) cmd.PersistentFlags().Duration("poll-interval", 500*time.Millisecond, "Interval at which to poll information, for example action progress") cmd.PersistentFlags().Bool("quiet", false, "Only print error messages") - cmd.SetOut(os.Stdout) + cmd.PersistentPreRunE = func(cmd *cobra.Command, args []string) error { + out := os.Stdout if quiet, _ := cmd.Flags().GetBool("quiet"); quiet { - f, err := os.Open(os.DevNull) + var err error + out, err = os.Open(os.DevNull) if err != nil { return err } - cmd.SetOut(f) } + cmd.SetOut(out) return nil } return cmd