mirror of https://github.com/spf13/viper.git
Set default values when binding the whole flagset
This commit is contained in:
parent
590bfb59e5
commit
bf641426ac
8
viper.go
8
viper.go
|
@ -372,6 +372,14 @@ func (v *Viper) BindPFlags(flags *pflag.FlagSet) (err error) {
|
|||
}
|
||||
|
||||
err = v.BindPFlag(flag.Name, flag)
|
||||
switch flag.Value.Type() {
|
||||
case "int", "int8", "int16", "int32", "int64":
|
||||
v.SetDefault(flag.Name, cast.ToInt(flag.Value.String()))
|
||||
case "bool":
|
||||
v.SetDefault(flag.Name, cast.ToBool(flag.Value.String()))
|
||||
default:
|
||||
v.SetDefault(flag.Name, flag.Value.String())
|
||||
}
|
||||
})
|
||||
return
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue