bur*_*ger 4 command-line docopt
这是来自 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.
Run Code Online (Sandbox Code Playgroud)
我发现该Options:部分中的选项可以有很长的解释。举个例子,很明显naval_fate --version就是Show version。
但是,有没有办法为命令或位置参数提供扩展解释?例如,用户如何知道naval_fate ship shoot <x> <y>做什么?
我带着同样的问题来到这里,我想我已经找到了解决方案。
文档字符串解析器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.
"""
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
494 次 |
| 最近记录: |