Issue 14504: Suggestion to improve argparse's help messages for "store_const" (original) (raw)
argparse's help messages for variables that use "store_const" can probably be improved:
- propagate the default to all the options
- mark the default option as such explicitly
- group the keywords that have the same destination together (?)
- place the default option first (?)
For example, wouldn't the attached .py be better served with a help message that looks like: ... optional arguments: -h, --help show this help message and exit -w, --wrench use a wrench (default) -H, --hammer use a hammer (default: wrench) -s, --screwdriver use a screwdriver (default: wrench) -T, --tnt just blow the whole thing up (default: wrench) --foo FOO foo bar (default: None)
?
Special casing the formatting of 'store_const' makes me nervous because formatting is already complicated and it doesn't know anything about action types.
But feel free to propose a patch!
In the meantime:
- propagate the default to all the options
You can, of course, do this manually, by specifying default in each of them. And if you use formatter_class=ArgumentDefaultsHelpFormatter, you'll get the defaults in the usage message.
- group the keywords that have the same destination together (?)
- place the default option first (?)
You can achieve both of these by just adding the options in the order that you want them displayed.