不知为何官方没有明确写出来,在此记录下:
##test.py
@click.command()
@click.option("--mode", "-m", show_default=True, default=0, type=click.INT, help="generation mode")
def cli(mode):
pass
if __main__ == "__name__":
cli()
调用时就可以使用:
python test.py --mode
#or
python test.py -m