3

这是来自 docopt.org 的示例:

Naval Fate.

Usage:
  naval_fate ship new <name>...
  naval_fate ship <name> move <x> <y> [--speed=<kn>]
  naval_fate ship shoot <x> <y>
  naval_fate mine (set|remove) <x> <y> [--moored|--drifting]
  naval_fate -h | --help
  naval_fate --version

Options:
  -h --help     Show this screen.
  --version     Show version.
  --speed=<kn>  Speed in knots [default: 10].
  --moored      Moored (anchored) mine.
  --drifting    Drifting mine.

我看到选项可以在该Options:部分中有很长的解释。例如,很明显naval_fate --version就是 to Show version

但是,有没有办法为命令或位置参数提供扩展解释?例如,用户如何知道做什么naval_fate ship shoot <x> <y>

4

1 回答 1

4

我带着同样的问题来到这里,我想我已经找到了解决方案。

文档字符串解析器不是很聪明或不严谨,这docopt是一件好事,因为这意味着您可以将各种其他信息放入您的文档字符串中而不会混淆docopt。例如,没有什么可以阻止Commands:Arguments:docstring. 这是我目前正在处理的项目的文档字符串:

"""Helioplot.

Retrieve and plot heliometer results.

Usage:
    helioplot fetch <root_dir_path> --host=<host> --password=<password> [--port=<port>] [--database=<database>] [--username=<username>]

Commands:
    fetch <root_dir_path>   Fetch and dump data into the directory specified
                            by <root_dir_path>.

Options:
    -h --help               Show this screen.
    --version               Show version.
    --host=<host>           The address of the computer hosting the database
    --port=<port>           The port number on which the database can be
                            accessed.
    --database=<database>   The name of the database.
    --username=<username>   A database username.
    --password=<password>   The database password.
"""
于 2017-04-17T14:37:59.147 回答