mirror of
https://github.com/spf13/viper
synced 2024-11-04 20:27:02 +00:00
Set default values when binding the whole flagset
This commit is contained in:
parent
19ed496472
commit
c861bdefb7
1 changed files with 8 additions and 0 deletions
8
viper.go
8
viper.go
|
@ -429,6 +429,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
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue