Set default values when binding the whole flagset

This commit is contained in:
Kiril Zvezdarov 2015-04-01 21:42:06 -04:00
parent 590bfb59e5
commit bf641426ac
1 changed files with 8 additions and 0 deletions

View File

@ -372,6 +372,14 @@ func (v *Viper) BindPFlags(flags *pflag.FlagSet) (err error) {
} }
err = v.BindPFlag(flag.Name, flag) 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 return
} }