From fbd655b2da0de9fc952d008076c07ae7f5d72bdc Mon Sep 17 00:00:00 2001 From: Ryan Cavicchioni Date: Sun, 28 Aug 2022 09:45:34 -0500 Subject: [PATCH] Respect the debug flag in the environment --- bot/config.go | 1 + cmd/bb/main.go | 9 +++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/bot/config.go b/bot/config.go index ed534ce..3b17cfa 100644 --- a/bot/config.go +++ b/bot/config.go @@ -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"` diff --git a/cmd/bb/main.go b/cmd/bb/main.go index 77ba6d6..395cb02 100644 --- a/cmd/bb/main.go +++ b/cmd/bb/main.go @@ -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) + } }