Move flags to init()

This commit is contained in:
Ryan Cavicchioni 2022-09-08 01:45:16 -05:00
parent 7ff6e74148
commit a151b08142
Signed by: ryanc
GPG Key ID: 877EEDAF9245103D

View File

@ -1,7 +1,6 @@
package bot package bot
import ( import (
"flag"
"fmt" "fmt"
"os" "os"
"os/signal" "os/signal"
@ -25,6 +24,13 @@ type (
MessageHandler func(s *discordgo.Session, m *discordgo.MessageCreate) MessageHandler func(s *discordgo.Session, m *discordgo.MessageCreate)
) )
func init() {
pflag.Bool("debug", false, "enable debug mode")
pflag.Parse()
viper.BindPFlags(pflag.CommandLine)
}
func NewBot(s *discordgo.Session, config Config) *Bot { func NewBot(s *discordgo.Session, config Config) *Bot {
return &Bot{Session: s, Config: config} return &Bot{Session: s, Config: config}
} }
@ -114,11 +120,6 @@ func setupConfig() {
C = NewConfig() C = NewConfig()
flag.Bool("debug", false, "enable debug logging")
pflag.CommandLine.AddGoFlagSet(flag.CommandLine)
pflag.Parse()
viper.BindPFlags(pflag.CommandLine)
viper.SetEnvPrefix("BEEPBOOP") viper.SetEnvPrefix("BEEPBOOP")
viper.AutomaticEnv() viper.AutomaticEnv()