forked from mirror/viper
Better binding to Pflag
This commit is contained in:
parent
7c42740ea6
commit
1cebee8d97
10
viper.go
10
viper.go
|
@ -123,7 +123,15 @@ func BindPFlag(key string, flag *pflag.Flag) (err error) {
|
|||
return fmt.Errorf("flag for %q is nil", key)
|
||||
}
|
||||
pflags[key] = flag
|
||||
SetDefault(key, flag.Value.String())
|
||||
|
||||
switch flag.Value.Type() {
|
||||
case "int", "int8", "int16", "int32", "int64":
|
||||
SetDefault(key, cast.ToInt(flag.Value.String()))
|
||||
case "bool":
|
||||
SetDefault(key, cast.ToBool(flag.Value.String()))
|
||||
default:
|
||||
SetDefault(key, flag.Value.String())
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue