Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

flagSet type is always string #138

Open
bldrdash opened this issue Nov 3, 2022 · 2 comments
Open

flagSet type is always string #138

bldrdash opened this issue Nov 3, 2022 · 2 comments

Comments

@bldrdash
Copy link

bldrdash commented Nov 3, 2022

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.

@bldrdash bldrdash closed this as not planned Won't fix, can't repro, duplicate, stale Nov 3, 2022
@cristaloleg
Copy link
Member

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!

@cristaloleg cristaloleg reopened this Nov 3, 2022
@bldrdash
Copy link
Author

bldrdash commented Nov 3, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants