从命令行参数分派到函数
docopt-dispatch的Python项目详细描述
实验性的。
示例
"""Run something in development or production mode. Usage: run.py --development <host> <port> run.py --production <host> <port> run.py remote add <item> run.py remote delete <item> """fromdocopt_dispatchimportdispatch@dispatch.on('--development')defdevelopment(host,port,**kwargs):print('in *development* mode')@dispatch.on('--production')defdevelopment(host,port,**kwargs):print('in *production* mode')@dispatch.on('items','add')defitems_add(item,**kwargs):print('adding item...')@dispatch.on('items','delete')defitems_delete(item,**kwargs):print('deleting item...')if__name__=='__main__':dispatch(__doc__)