diff --git a/internal/cmd/root/root.go b/internal/cmd/root/root.go index 7bd95e1b..cc2c9e1b 100644 --- a/internal/cmd/root/root.go +++ b/internal/cmd/root/root.go @@ -60,12 +60,19 @@ func init() { viper.SetConfigType(jiraConfig.FileType) } - viper.AutomaticEnv() - viper.SetEnvPrefix("jira") + if err := viper.ReadInConfig(); err == nil { + if debug { + fmt.Printf("Using config file: %s\n", viper.ConfigFileUsed()) + } - if err := viper.ReadInConfig(); err == nil && debug { - fmt.Printf("Using config file: %s\n", viper.ConfigFileUsed()) + // Preserve config file token before AutomaticEnv binds JIRA_API_TOKEN. + if token := viper.GetString("api_token"); token != "" { + viper.Set("api_token", token) + } } + + viper.AutomaticEnv() + viper.SetEnvPrefix("jira") }) }