pythonpython-click

Python click, Can you make -h as an alias


I have recently found the click library (http://click.pocoo.org/6/) and I love it.

I am trying to figure out if it is possible to create an alias for the --help option which shortcuts to the help. So, for example:

app.py --help

gives the help for the main app and

app.py sub --help

will give the help for the sub. I want to be able to use -h as well. If I were creating the option, it may look something like:

@click.option('-h', '--help')

but the --help option is built in. Is there a way to extend that option or create an alias for it?


Solution

  • Well, I found it:

    https://click.palletsprojects.com/en/7.x/documentation/#help-parameter-customization

    @click.command(context_settings=dict(help_option_names=["-h", "--help"]))
    def cli():
        pass