Python Click使用命令行短参数(short option)

不知为何官方没有明确写出来,在此记录下:

##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 0
#or
python test.py -m 0

猜你喜欢

转载自blog.csdn.net/tp7309/article/details/72785538