Skip to content

Commit

Permalink
fix: Flags with hyphens were skipped with config from ENV (open-polic…
Browse files Browse the repository at this point in the history
…y-agent#612)

Previously when a viper.GetX call was made for a flag with a hypen in
it, if that was set via the environment it would fail because viper's
internal store had it as a value with an underscore instead of a hyphen.
By adding this replacer the conversion happens automatically for
configuration in the environment without affecting the existing flags.

Signed-off-by: James Alseth <james@jalseth.me>
  • Loading branch information
jalseth authored and macox committed Oct 5, 2021
1 parent 8d86adf commit a58c2a3
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions internal/commands/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"log"
"os"
"strings"

"github.com/open-policy-agent/conftest/plugin"

Expand All @@ -30,6 +31,7 @@ func NewDefaultCommand() *cobra.Command {
cmd.SetVersionTemplate(`{{.Version}}`)

viper.SetEnvPrefix("CONFTEST")
viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_"))
viper.SetConfigName("conftest")
viper.AddConfigPath(".")
viper.AutomaticEnv()
Expand Down

0 comments on commit a58c2a3

Please # to comment.