akamensky / argparse

Argparse for golang. Just because `flag` sucks
MIT License
604 stars 62 forks source link

Add support for "default" values #7

Closed jvanmalder closed 6 years ago

jvanmalder commented 6 years ago

See https://docs.python.org/3/library/argparse.html#default.

I would expect something like:

parser.String("s", "string", &argparse.Options{Default: "The default string value."})

akamensky commented 6 years ago

@jvanmalder Thanks for your suggestion, I considered this option, however this might be more complex than it is in Python due to strict typing of Go. Currently argparse.Options is the same for all of argument types, and with strict type checking I can't put the default value there directly. One option would be to make argparse.Options.Default an interface {} type, but that would require type checking for each single argument.

Feel free to provide your ideas on how to implement this, or even better would be a pull request :)

fingon commented 6 years ago

I would prefer to see just interface{}d Default attribute, which then would be typecast at parse time so (beyond the Options struct setup) the code would still stay typesafe.

akamensky commented 6 years ago

@fingon thanks, I was thinking the same, made the branch features/default-value, feel free to send PR there as I am a little swamped right now and it may take some time for me to get to that one.

akamensky commented 6 years ago

I've just added default values functionality (&argparse.Options{Default:...}). Would appreciate any bug reports on this.

Meanwhile I will close this issue.