Respect the debug flag in the environment

This commit is contained in:
Ryan Cavicchioni 2022-08-28 09:45:34 -05:00
parent 7d071ebe0b
commit fbd655b2da
Signed by: ryanc
GPG Key ID: 877EEDAF9245103D
2 changed files with 6 additions and 4 deletions

View File

@ -10,6 +10,7 @@ var (
type (
Config struct {
Debug bool `mapstructure:"debug"`
Handler HandlerConfig `mapstructure:"handler"`
Prefix string `mapstructure:"prefix"`
DiscordToken string `mapstructure:"discord_token"`

View File

@ -83,10 +83,6 @@ func setupConfig() {
pflag.Parse()
viper.BindPFlags(pflag.CommandLine)
if viper.GetBool("debug") {
log.SetLevel(log.DebugLevel)
}
viper.SetEnvPrefix("BEEPBOOP")
viper.AutomaticEnv()
@ -96,6 +92,7 @@ func setupConfig() {
err = viper.ReadInConfig()
viper.BindEnv("DEBUG")
viper.BindEnv("DISCORD_TOKEN")
viper.BindEnv("OPEN_WEATHER_MAP_TOKEN")
@ -107,4 +104,8 @@ func setupConfig() {
if err != nil {
log.Fatalf("unable to decode into struct: %v", err)
}
if viper.GetBool("debug") {
log.SetLevel(log.DebugLevel)
}
}