From c65f7270a9c46d5740ea53578fb416cd63d00c25 Mon Sep 17 00:00:00 2001 From: andig Date: Sun, 19 Feb 2023 15:27:19 +0100 Subject: [PATCH] Register all known config elements as ENV keys --- cmd/root.go | 9 +++++++++ 1 file changed, 9 insertions(+) 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())