python / cpython

The Python programming language
https://www.python.org
Other
62.56k stars 30.02k forks source link

feature request: --advanced-help feature for argparse #98664

Open kenyee opened 1 year ago

kenyee commented 1 year ago

Feature or enhancement

We have a complex CLI tool in python that our users use and we'd like to hide some parameters as "advanced" so they only show w/ a --advanced-help command.

Pitch

Some parameters are useful for debugging of the script or for advanced features that most users won't care about. It would be nice to hide these from the common parameters you can see w/ the -h output.

Previous discussion

https://discuss.python.org/t/advanced-help-for-argparse/20319

hpaulj commented 1 year ago

A quick idea inspired by the linked discussion.

You could put these advanced arguments in a new Action_group. The parser.format_help function supplies all groups to the HelpFormatter. I can see writing two format_help functions, one that passes all, and other that passes all but this 'advanced' group. Then reconfigure the default help to uses the selective one, and the '--advanced_help' uses the 'all' one.

For a start such a feature should be implemented and tested in your own code, and maybe published as a pypi. If well tested might be added as a feature of the default argparse.