Set default values when binding the whole flagset

This commit is contained in:
Kiril Zvezdarov 2015-04-01 21:42:06 -04:00
parent 19ed496472
commit c861bdefb7

View file

@ -429,6 +429,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
}