Skip to content

Commit

Permalink
cmd: allow to customize nested options via env variables
Browse files Browse the repository at this point in the history
As most shells don't allow dots in environment variable names, it's not
possible to customize nested options via environment variable, like:

PROMU_BUILD_FLAGS='<flags>'

The patch fixes this by asking viper to replace all dots in config key
names with '_' while scanning the environment.

Signed-off-by: Pavel Borzenkov <pavel.borzenkov@gmail.com>
  • Loading branch information
pborzenkov committed Jun 23, 2018
1 parent ad773dd commit 94a5b5e
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion cmd/promu.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ func initConfig() error {
viper.SetConfigName(".promu") // name of config file (without extension)
viper.AddConfigPath(".") // look for config in the working directory
viper.SetEnvPrefix("promu")
viper.AutomaticEnv() // read in environment variables that match
viper.AutomaticEnv() // read in environment variables that match
viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_")) // replacing dots in key names with '_'

// If a config file is found, read it in.
if err := viper.ReadInConfig(); err != nil {
Expand Down

0 comments on commit 94a5b5e

Please sign in to comment.