feat(backup): use logrus for output
This commit is contained in:
parent
0c05b9ee2c
commit
0c093bb5c9
5 changed files with 23 additions and 18 deletions
|
@ -7,6 +7,7 @@ import (
|
|||
|
||||
"git.ar21.de/yolokube/grafana-backuper/internal/config"
|
||||
"git.ar21.de/yolokube/grafana-backuper/internal/version"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/pflag"
|
||||
"github.com/spf13/viper"
|
||||
|
@ -20,20 +21,18 @@ func NewRootCommand(c *config.Config) *cobra.Command {
|
|||
Short: "Grafana Backuper CLI",
|
||||
Long: "A command-line tool to back up and restore Grafana dashboards",
|
||||
Version: version.Version(),
|
||||
PersistentPreRunE: func(cmd *cobra.Command, _ []string) error {
|
||||
PersistentPreRun: func(cmd *cobra.Command, _ []string) {
|
||||
initializeConfig(cmd)
|
||||
|
||||
c.Output = os.Stdout
|
||||
if c.Quiet {
|
||||
var err error
|
||||
c.Output, err = os.Open(os.DevNull)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
log.SetOutput(c.Output)
|
||||
log.SetLevel(log.InfoLevel)
|
||||
cmd.SetOut(c.Output)
|
||||
return nil
|
||||
|
||||
if c.Debug {
|
||||
log.SetLevel(log.DebugLevel)
|
||||
}
|
||||
},
|
||||
SilenceUsage: true,
|
||||
}
|
||||
|
@ -47,7 +46,6 @@ func NewRootCommand(c *config.Config) *cobra.Command {
|
|||
rootCmd.PersistentFlags().StringVar(&c.GitRepo, "git-repo", "", "Complete Git repository URL")
|
||||
rootCmd.PersistentFlags().StringVar(&c.GitUser, "git-user", "", "Git user name")
|
||||
rootCmd.PersistentFlags().StringVar(&c.GitPass, "git-pass", "", "Git user password")
|
||||
rootCmd.PersistentFlags().BoolVarP(&c.Quiet, "quiet", "q", false, "Mute console output")
|
||||
|
||||
return rootCmd
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue