package cmd import ( log "github.com/sirupsen/logrus" "github.com/spf13/cobra" "github.com/spf13/viper" "udico.de/uditaren/loadmaster2k/config" . "udico.de/uditaren/loadmaster2k/config" ) var cRoot = &cobra.Command{ Use: "loadmaster ", Short: "Monitor the boulder area load", } func init() { cRoot.PersistentPreRunE = preRun cRoot.PersistentFlags().BoolP("debug", "d", false, "Enable debug output") viper.BindPFlag("debug", cRoot.PersistentFlags().Lookup("debug")) } func Execute() { if err := cRoot.Execute(); err != nil { log.WithError(err).Error("cannot execute command") } } func preRun(cmd *cobra.Command, args []string) error { config.LoadConfiguration() initLogger(cmd, args) return nil } // Set the log level according to initial command line flags func initLogger(cmd *cobra.Command, args []string) { switch { case C.Debug: log.SetLevel(log.DebugLevel) //case C.Supersilent: // log.SetLevel(log.ErrorLevel) //case C.Silent: // log.SetLevel(log.WarnLevel) } }