Python优雅命令行工具接口 click使用
解析不清楚,直接上代码
import click
@click.command()
@click.option('--count', default=1, help='Number of greetings.')
@click.option('--name', prompt='Your name',
help='The person to greet.')
def hello(count, name):
"""Simple program that greets NAME for a total of COUNT times."""
for x in range(count):
click.echo('Hello %s!' % name)
if __name__ == '__main__':
hello()
运行输出如下,help用于参数说明,default用于设置默认值
$ python hello.py --count=3
Your name: John
Hello John!
Hello John!
Hello John!