forked from mirror/viper
ensure BindPFlag() detects a nil flag parameter before wrapping in pflagValue.
This commit is contained in:
parent
d9d7dcdc63
commit
a0285163e1
3
viper.go
3
viper.go
|
@ -992,6 +992,9 @@ func (v *Viper) BindPFlags(flags *pflag.FlagSet) error {
|
|||
func BindPFlag(key string, flag *pflag.Flag) error { return v.BindPFlag(key, flag) }
|
||||
|
||||
func (v *Viper) BindPFlag(key string, flag *pflag.Flag) error {
|
||||
if flag == nil {
|
||||
return fmt.Errorf("flag for %q is nil", key)
|
||||
}
|
||||
return v.BindFlagValue(key, pflagValue{flag})
|
||||
}
|
||||
|
||||
|
|
|
@ -970,6 +970,11 @@ func TestBindPFlag(t *testing.T) {
|
|||
assert.Equal(t, "testing_mutate", Get("testvalue"))
|
||||
}
|
||||
|
||||
func TestBindPFlagDetectNilFlag(t *testing.T) {
|
||||
result := BindPFlag("testvalue", nil)
|
||||
assert.Error(t, result)
|
||||
}
|
||||
|
||||
func TestBindPFlagStringToString(t *testing.T) {
|
||||
tests := []struct {
|
||||
Expected map[string]string
|
||||
|
|
Loading…
Reference in New Issue