package cmd import ( "github.com/bdlm/log" "github.com/spf13/cobra" ) var ( debug bool timestamps bool ) // RootCMD represents the base command when called without any subcommands var RootCMD = &cobra.Command{ Use: "meetandeat", } // Execute adds all child commands to the root command and sets flags appropriately. // This is called by main.main(). It only needs to happen once to the RootCMD. func Execute() { if err := RootCMD.Execute(); err != nil { log.Error(err) } } func init() { cobra.OnInitialize(func() { if debug { log.SetLevel(log.DebugLevel) } log.SetFormatter(&log.TextFormatter{ DisableTimestamp: timestamps, }) log.Debug("show debug") }) RootCMD.PersistentFlags().BoolVar(&debug, "v", false, "show debug log") RootCMD.PersistentFlags().BoolVar(×tamps, "timestamps", false, "Enables timestamps for log output") }