首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用--docopt解释命令和位置参数

使用--docopt解释命令和位置参数
EN

Stack Overflow用户
提问于 2017-04-09 04:25:05
回答 1查看 296关注 0票数 3

这是来自docopt.org的示例:

代码语言:javascript
复制
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是对Show version而言的。

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

EN

回答 1

Stack Overflow用户

发布于 2017-04-17 22:37:59

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

docopt文档字符串解析器不是非常聪明或严格,这是一件好事,因为它意味着您可以在文档字符串中放入所有其他类型的信息,而不会混淆docopt。例如,没有什么可以阻止您向docstring添加Commands:Arguments:部分。下面是我目前正在处理的项目的文档字符串:

代码语言:javascript
复制
"""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.
"""
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43300005

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档