V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
FindHao
V2EX  ›  编程

命令行工具的 usage 有什么编写规范吗

  •  
  •   FindHao · 2017-01-16 16:12:41 +08:00 · 4120 次点击
    这是一个创建于 2658 天前的主题,其中的信息可能已经有所发展或是发生改变。

    有没有一个统一的规范写法?

    1 条回复    2017-01-16 16:35:26 +08:00
    Kilerd
        1
    Kilerd  
       2017-01-16 16:35:26 +08:00
    简单地 google 了下 “ the standard of program usage ” or "the standard of cli help"

    给几个感觉可以的链接:
    http://stackoverflow.com/questions/9725675/is-there-a-standard-format-for-command-line-shell-help-text
    http://courses.cms.caltech.edu/cs11/material/general/usage.html
    https://technet.microsoft.com/en-us/library/ee156811.aspx 这是微软的标准

    其实这个并不用自己写,很多优秀的库都支持自动生成这个 help 信息

    Python 中的 Click , Rust 中的 Clap

    这些都是你在程序中定义了变量或者 subcommand 之后会自动生成 --help 或者 -h 里面的内容。

    如果说要看规范的化,建议查查 RFC 文档。

    不过强烈建议先看看自己写的语言里面有没有类似的库,有就没必要手写了。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   906 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 22:22 · PVG 06:22 · LAX 15:22 · JFK 18:22
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.