diff --git a/internal/pkg/command/log.go b/internal/pkg/command/log.go index e78b12d..cd6cf30 100644 --- a/internal/pkg/command/log.go +++ b/internal/pkg/command/log.go @@ -2,6 +2,7 @@ package command import ( "bytes" + "io" "os" "strings" @@ -46,3 +47,9 @@ func (f cliFormatter) Format(entry *logrus.Entry) ([]byte, error) { b.WriteString("\n") return b.Bytes(), nil } + +func initLogging() { + if !showOutput { + logrus.SetOutput(io.Discard) + } +} diff --git a/internal/pkg/command/root.go b/internal/pkg/command/root.go index f23622b..6cf2c2a 100644 --- a/internal/pkg/command/root.go +++ b/internal/pkg/command/root.go @@ -1,7 +1,6 @@ package command import ( - "io" "os" "github.com/nousefreak/projecthelper/internal/pkg/config" @@ -12,7 +11,7 @@ import ( var ( cmdName = "ph" - quite bool + showOutput bool ) func getRootCmd() *cobra.Command { @@ -31,7 +30,7 @@ func getRootCmd() *cobra.Command { getGoCmd().Run(cmd, args) }, } - rootCmd.PersistentFlags().BoolVarP(&quite, "quite", "q", true, "Hide output") + rootCmd.PersistentFlags().BoolVar(&showOutput, "show-output", true, "Show output") return rootCmd } @@ -50,14 +49,10 @@ func Execute() { rootCmd.AddCommand(getTmuxCmd()) cobra.OnInitialize(config.InitConfig) + cobra.OnInitialize(initLogging) rootCmd.SetOut(os.Stderr) - if quite { - logrus.SetOutput(io.Discard) - rootCmd.SetOut(io.Discard) - } - if err := rootCmd.Execute(); err != nil { logrus.Fatal(err) }