为什么docopt解析完参数后退出脚本?

Why does docopt exits the script after parsing the parameters?

我使用 docopt 有一段时间了,在新脚本上我无法通过参数解析:

# coding=utf-8
"""
API server for the infoscreen frontends

Usage:
    python3 webserver.py [options]

Options:
    --bind ADDRESS  address to bind to  [default: 0.0.0.0]
    --galarmclock URL  URL for the galarmclock API [default: http://10.100.10.202:8082]
    --loglevel LOG  logging level   [default: logging.DEBUG]
    --console   log to console [default: False]
    --syslog    log to syslog [default: False]

"""

import docopt

# process arguments
args = docopt.docopt(__doc__)
print(args)

所有参数(参数)都是可选的并且有一个默认值那么为什么脚本会停止?

C:\Python3\python.exe C:/tst.py
Usage:
    python3 webserver.py [options]

Process finished with exit code 1

问题出在使用部分:

Usage:
    python3 webserver.py [options]

Docopt 期望使用部分的第一个字符串是您的程序,而不是 python。所以 docopt 将把它解释为 python3 是你的程序,并且它总是接受一个名为 webserver.py 的命令。如果您删除 python3 部分,它应该可以像这样正常工作:

Usage:
    webserver.py [options]

docopt's documentation 我们有:

Text occuring between keyword usage: (case-insensitive) and a visibly empty line is interpreted as list of usage patterns. The first word after usage: is interpreted as the program's name.