How do I specify both a short option and long option for the same option?
e.g., for the following, I also want to use -c
for --count
:
import click
@click.command()
@click.option('--count', default=1, help='count of something')
def my_command(count):
click.echo('count=[%s]' % count)
if __name__ == '__main__':
my_command()
e.g.,
$ python my_command.py --count=2
count=[2]
$ python my_command.py -c 3
count=[3]
References:
click documentation in a single pdf
click sourcecode on github
click website
click PyPI page
For windows: Hold down the control (ctrl) button to select multiple options. For Mac: Hold down the command button to select multiple options.
Click is a Python package for creating beautiful command line interfaces in a composable way with as little code as necessary. It's the “Command Line Interface Creation Kit”. It's highly configurable but comes with sensible defaults out of the box.
Open your Linux terminal or shell. Type “ pip install click ” (without quotes), hit Enter. If it doesn't work, try "pip3 install click" or “ python -m pip install click “. Wait for the installation to terminate successfully.
When a Click command callback is executed, it's passed all the non-hidden parameters as keyword arguments. Notably absent is the context. However, a callback can opt into being passed to the context object by marking itself with pass_context() .
This is not well documented, but is quite straight forward:
@click.option('--count', '-c', default=1, help='count of something')
Test Code:
@click.command()
@click.option('--count', '-c', default=1, help='count of something')
def my_command(count):
click.echo('count=[%s]' % count)
if __name__ == '__main__':
my_command(['-c', '3'])
Result:
count=[3]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With