天天看点

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