天天看點

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