diff --git a/cmd/root.go b/cmd/root.go index ba81e9d241..033d934e51 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -60,6 +60,12 @@ var rootCmd = &cobra.Command{ func init() { viper = vpr.NewWithOptions(vpr.ExperimentalBindStruct()) + viper.SetEnvPrefix("evcc") + viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_")) + viper.AutomaticEnv() // read in environment variables that match + + util.LogLevel("info", nil) + cobra.OnInitialize(initConfig) // global options @@ -105,14 +111,6 @@ func initConfig() { if cfgDatabase != "" { viper.Set("Database.Dsn", cfgDatabase) } - - viper.SetEnvPrefix("evcc") - viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_")) - viper.AutomaticEnv() // read in environment variables that match - - // print version - util.LogLevel("info", nil) - log.INFO.Printf("evcc %s", util.FormattedVersion()) } // Execute adds all child commands to the root command and sets flags appropriately. @@ -126,6 +124,9 @@ func Execute() { func runRoot(cmd *cobra.Command, args []string) { runAsService = true + // print version + log.INFO.Printf("evcc %s", util.FormattedVersion()) + // load config and re-configure logging after reading config file var err error if cfgErr := loadConfigFile(&conf, !cmd.Flag(flagIgnoreDatabase).Changed); errors.As(cfgErr, &vpr.ConfigFileNotFoundError{}) {