diff --git a/cmd/root.go b/cmd/root.go index c4ed0023c..12d88806e 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -21,6 +21,9 @@ import ( "github.com/evcc-io/evcc/util/pipe" "github.com/evcc-io/evcc/util/sponsor" "github.com/evcc-io/evcc/util/telemetry" + "github.com/fatih/structs" + "github.com/jeremywohl/flatten" + "golang.org/x/exp/maps" _ "github.com/joho/godotenv/autoload" "github.com/prometheus/client_golang/prometheus/promhttp" @@ -89,6 +92,12 @@ func initConfig() { viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_")) viper.AutomaticEnv() // read in environment variables that match + // register all known config keys + flat, _ := flatten.Flatten(structs.Map(conf), "", flatten.DotStyle) + for _, v := range maps.Keys(flat) { + viper.BindEnv(v) + } + // print version util.LogLevel("info", nil) log.INFO.Printf("evcc %s", server.FormattedVersion())