Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 300
Jeff Avatar asked Dec 09 '15 15:12

Jeff


People also ask

How do you make a click option in Python?

Python click option namesClick derives the name of the option from the long name, if both are used. In the example, we create an option with both short and long names. The name of the variable passed to the function is string , derived from the longer option name. We run the program using both option names.


Video Answer


1 Answers

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
like image 70
Jeff Avatar answered Oct 17 '22 22:10

Jeff