FindHao
V2EX  ›  编程

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

  •  
  •   FindHao · Jan 16, 2017 · 4635 views
    This topic created in 3433 days ago, the information mentioned may be changed or developed.

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

    1 replies    2017-01-16 16:35:26 +08:00
    Kilerd
        1
    Kilerd  
       Jan 16, 2017
    简单地 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 文档。

    不过强烈建议先看看自己写的语言里面有没有类似的库,有就没必要手写了。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   982 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 19:27 · PVG 03:27 · LAX 12:27 · JFK 15:27
    ♥ Do have faith in what you're doing.