mirror of
https://github.com/spf13/viper
synced 2024-12-22 03:27:03 +00:00
Better binding to Pflag
This commit is contained in:
parent
7c42740ea6
commit
1cebee8d97
1 changed files with 9 additions and 1 deletions
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 a new issue