lebrice / SimpleParsing

Simple, Elegant, Typed Argument Parsing with argparse
MIT License
401 stars 50 forks source link

Small help presentation changes #90

Closed haydenflinner closed 2 years ago

haydenflinner commented 2 years ago

Is your feature request related to a problem? Please describe. Two minor things I would like to tweak in the help: 1, I'd like to remove the call-outs to what dataclass is being populated, in favor of these not being exposed. 2, I'd like to display "-"s instead of "_"s, because I don't want my users to think they have to hold shift between letters when typing argument names :smile:

usage: my-prog my_cmd [-h] --path str [--int_var int]

optional arguments:
  -h, --help     show this help message and exit

MyCmdArgs ['dataclass_arg']:
  MyCmdArgs(path:str, freq_ms:int=1000)

  --path str
  --int_var int  (default: 1000)

would become

usage: my-prog my_cmd [-h] --path str [--int-var int]

optional arguments:
  -h, --help     show this help message and exit
  --path str
  --int-var int  (default: 1000)

I poked around help_formatter.py but it's not obvious to me where this little section with the constructor of the class's signature is coming from. Could probably find by spending time later in a debugger. It is somewhat obvious where the "_"'s in the help come from, and I will check later if it's trivial to add an option to switch these to "-"'s as a user of the lib.

Thank you!

lebrice commented 2 years ago

Hey @haydenflinner thanks for posting this. It seem to me like you're looking for the "add_option_string_dash_variants" argument to ArgumentParser, although, (as mentioned previously in some other issue i'll link here), this adds the alternative option strings where the underscores are replaced with dashes. There isn't yet an option for only using the dash variant.

Hope this helps for now! And by the way, the main thing to look at is the FieldWrapper, which generates the arg_options which are then passed to parser.add_argument(**arg_options).