From beef8c6692ff9f2d49aa6e301d268e80c5cc02dc Mon Sep 17 00:00:00 2001 From: comp500 <comp500@users.noreply.github.com> Date: Thu, 6 Jul 2023 04:56:58 +0100 Subject: [PATCH] Add prefix to env variable lookup, replace . with _ e.g. $PACKWIZ_INIT_REINIT is equivalent to the -r flag --- cmd/root.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cmd/root.go b/cmd/root.go index b7511d2..4e016a9 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -6,6 +6,7 @@ import ( "github.com/spf13/pflag" "os" "path/filepath" + "strings" "github.com/spf13/cobra" "github.com/spf13/viper" @@ -92,7 +93,10 @@ func initConfig() { viper.SetConfigName(".packwiz") } - viper.AutomaticEnv() // read in environment variables that match + // Read in environment variables that match + viper.SetEnvPrefix("packwiz") + viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_")) + viper.AutomaticEnv() // If a config file is found, read it in. if err := viper.ReadInConfig(); err == nil {