loadmaster2k/cmd/root.go

46 lines
1014 B
Go
Raw Normal View History

2020-10-27 21:43:11 +01:00
package cmd
import (
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
2020-10-28 11:33:38 +01:00
"github.com/spf13/viper"
"udico.de/uditaren/loadmaster2k/config"
. "udico.de/uditaren/loadmaster2k/config"
2020-10-27 21:43:11 +01:00
)
var cRoot = &cobra.Command{
Use: "loadmaster <command>",
Short: "Monitor the boulder area load",
}
func init() {
2020-10-28 11:33:38 +01:00
cRoot.PersistentPreRunE = preRun
2020-10-27 21:43:11 +01:00
2020-10-28 11:33:38 +01:00
cRoot.PersistentFlags().BoolP("debug", "d", false, "Enable debug output")
viper.BindPFlag("debug", cRoot.PersistentFlags().Lookup("debug"))
2020-10-27 21:43:11 +01:00
}
func Execute() {
if err := cRoot.Execute(); err != nil {
log.WithError(err).Error("cannot execute command")
}
}
2020-10-28 11:33:38 +01:00
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)
}
}