Skip to content

Commit

Permalink
fix: Correct hiding output
Browse files Browse the repository at this point in the history
  • Loading branch information
NoUseFreak committed Jan 9, 2024
1 parent 52f1cad commit cc4ce6d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
7 changes: 7 additions & 0 deletions internal/pkg/command/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package command

import (
"bytes"
"io"
"os"
"strings"

Expand Down Expand Up @@ -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)
}
}
11 changes: 3 additions & 8 deletions internal/pkg/command/root.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package command

import (
"io"
"os"

"github.com/nousefreak/projecthelper/internal/pkg/config"
Expand All @@ -12,7 +11,7 @@ import (
var (
cmdName = "ph"

quite bool
showOutput bool
)

func getRootCmd() *cobra.Command {
Expand All @@ -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
}

Expand All @@ -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)
}
Expand Down

0 comments on commit cc4ce6d

Please sign in to comment.