我也有同样的问题。
我找不到解决方案,但这是我所拥有的最佳解决方法:
"""
Usage:
test.py [tls [--true|--false]]
"""
from docopt import docopt
arguments = docopt(__doc__)
if arguments['tls'] and not (arguments['--true'] or arguments['--false']):
arguments['--true'] = True
所以参数选项是:
cmd
cmd tls
cmd tls --true
cmd tls --false
注意这是区分大小写的,如果你把TLS大写可能会有错误:https://github.com/docopt/docopt/issues/460
另一种选择:
"""
Usage:
script.py [--tls [<tlsval>]]
"""
from docopt import docopt
arguments = docopt(__doc__)
assert arguments['<tlsval>'] in (None, 'true', 'false'), "invalid tls value -- expected true or false"
抱歉所有的修改,但这里还有一个:
"""
Usage:
script.py [--MAS|--GPI [RESEND|ADD|REMOVE|SKU]]
Options:
--MAS only do MAS step
--GPI only do GPI step, optionally specify ADD/REMOVE/SKU (default is RESEND)
RESEND only GPI, strategy=RESEND (default for --GPI)
ADD only GPI, strategy=ADD
REMOVE only GPI, strategy=REMOVE
SKU only GPI, strategy=SKU
"""
from docopt import docopt
arguments = docopt(__doc__)
strategy = [k for k in ['RESEND', 'ADD', 'REMOVE', 'SKU'] if arguments[k]]
strategy = strategy[0] if strategy else "RESEND" #resend is default
这个给你--argument但不能在--argument之后有=