aconfig
aconfig copied to clipboard
flagSet type is always string
I find this module a great alternative to viper when using Cobra, but miss the help output that identifies the type of the flag. Right now, all flags return as string
type Config struct {
Home string `env:"HOME" required:"true" usage:"Set home"`
Port int64 `default:"1111" usage:"Set int"`
WantBool bool `usage:"Set bool" flag:"wantbool"`
}
...
Produces:
Flags:
-h, --help help for cli
--home string Set home
--port string Set int (default "1111")
--wantbool string Set bool
Want:
Flags:
-h, --help help for cli
--home string Set home
--port int Set int (default 1111)
--wantbool Set bool
In the new-parser branch, parser.go 144 where it says TODO, is this where you'd expect to do something like:?
switch field.value.Type().Kind() {
case reflect.Bool:
boolVal, _ := strconv.ParseBool(field.Tag("default"))
l.flagSet.Bool(flagName, boolVal, field.Tag("usage"))
...
}
It's something I'd like to do but am not sure if you'll be merging new-parser in to main.
Sorry, haven't replied earlier. Yes, there is a problem like that, I hope I will finish with a new parser this week(s) and more good stuff will be done with other parts, including problem you've described.
I will reopen the issue just to make it more visible, hope you're not against that. Thanks!
No problem. I deleted it while I was deciding if I should fork and PR, or look to make more substantial changes. I'll fork for now and see where it goes. Thanks.