forked from mirror/viper
Set default values when binding the whole flagset
This commit is contained in:
parent
19ed496472
commit
c861bdefb7
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 New Issue