Skip to content

Commit

Permalink
Add prefix to env variable lookup, replace . with _
Browse files Browse the repository at this point in the history
e.g. $PACKWIZ_INIT_REINIT is equivalent to the -r flag
  • Loading branch information
comp500 committed Jul 6, 2023
1 parent 99d0af1 commit beef8c6
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/spf13/pflag"
"os"
"path/filepath"
"strings"

"github.com/spf13/cobra"
"github.com/spf13/viper"
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit beef8c6

Please sign in to comment.