如何在点击中为一个选项创建短选项和长选项(python 包)?
How to create both short and long options for one option in click (python package)?
如何为同一期权同时指定空头期权和多头期权?
例如,对于以下内容,我还想将 -c
用于 --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()
例如,
$ python my_command.py --count=2
count=[2]
$ python my_command.py -c 3
count=[3]
参考文献:
click documentation in a single pdf
click sourcecode on github
click website
click PyPI page
这没有很好的记录,但很简单:
@click.option('--count', '-c', default=1, help='count of something')
测试代码:
@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'])
结果:
count=[3]
如何为同一期权同时指定空头期权和多头期权?
例如,对于以下内容,我还想将 -c
用于 --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()
例如,
$ python my_command.py --count=2
count=[2]
$ python my_command.py -c 3
count=[3]
参考文献:
click documentation in a single pdf
click sourcecode on github
click website
click PyPI page
这没有很好的记录,但很简单:
@click.option('--count', '-c', default=1, help='count of something')
测试代码:
@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'])
结果:
count=[3]