refactor(internal/cmd): move backend cmd functions to grafanabackuper package
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Tom Neuber 2024-08-19 14:13:16 +02:00
parent 840008df2d
commit 83a15b5a87
Signed by: tom
GPG key ID: F17EFE4272D89FF6
7 changed files with 112 additions and 264 deletions

View file

@ -6,8 +6,10 @@ import (
"strings"
"git.ar21.de/yolokube/grafana-backuper/internal/config"
"git.ar21.de/yolokube/grafana-backuper/internal/logger"
"git.ar21.de/yolokube/grafana-backuper/internal/version"
log "github.com/sirupsen/logrus"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"github.com/spf13/viper"
@ -24,22 +26,27 @@ func NewRootCommand(c *config.Config) *cobra.Command {
PersistentPreRun: func(cmd *cobra.Command, _ []string) {
initializeConfig(cmd)
c.Output = os.Stdout
log.SetOutput(c.Output)
log.SetLevel(log.InfoLevel)
cmd.SetOut(c.Output)
// c.Output = os.Stdout
cmd.SetOut(os.Stdout)
zerolog.SetGlobalLevel(zerolog.InfoLevel)
if c.Debug {
log.SetLevel(log.DebugLevel)
zerolog.SetGlobalLevel(zerolog.DebugLevel)
}
if c.JSONFormat {
log.Logger = logger.JSONLoggerLayout(os.Stderr)
c.Logger = logger.JSONLoggerLayout(os.Stdout)
} else {
log.Logger = logger.CliLoggerLayout(os.Stderr)
c.Logger = logger.CliLoggerLayout(os.Stdout)
}
},
SilenceUsage: true,
}
rootCmd.SetErrPrefix("Error:")
rootCmd.PersistentFlags().BoolVarP(&c.Debug, "debug", "d", false, "Debug output")
rootCmd.PersistentFlags().BoolVar(&c.JSONFormat, "json", false, "JSON output")
rootCmd.PersistentFlags().StringVar(&c.GrafanaURL, "grafana-url", "", "Grafana URL to access the API")
rootCmd.PersistentFlags().StringVar(&c.GrafanaToken, "grafana-token", "", "Grafana auth token to access the API")
rootCmd.PersistentFlags().StringVar(&c.GitBranch, "git-branch", "main", "Git branch name")