hamdanal / rich-argparse

A rich help formatter for argparse
https://pypi.org/project/rich-argparse/
MIT License
129 stars 11 forks source link

Minor: Pretty formatting of default values #84

Closed baolsen closed 1 year ago

baolsen commented 1 year ago

Awesome plugin.

When using formatter_class=ArgumentDefaultsRichHelpFormatter

Currently the default values display fine but it would be nice to pretty-print them if possible. Example of current: image

I don't mind attempting a PR for it.

hamdanal commented 1 year ago

I agree, while in the other formatters you can use console markup to add special styles for defaults, this is not currently possible with ArgumentDefaultsRichHelpFormatter. I am not clear how to best handle this yet. There are multiple options for where this should go:

  1. If only for the ArgumentDefaultsRichHelpFormatter formatter: we need to override its _get_help_string method
  2. If for all formatters: this then has to go in the _rich_expand_help method

There is also the question about what needs to be considered for styling:

  1. Only the default value: "foo bar (default: [argparse.defaults]%(default)s[/argparse.defaults])"
  2. The default and the surrounding parenthesis: "foo bar[argparse.defaults](default: %(default)s)[argparse.defaults]". This may not always work if the user doesn't stick to the (default: %(default)s) format. I lean toward option 1 here.