如果没有,是否存在一个事实上的标准?基本上,我正在编写命令行帮助文本,如下所示:
usage: app_name [options] required_input required_input2
options:
-a, --argument Does something
-b required Does something with "required"
-c, --command required Something else
-d [optlistitem1 optlistitem 2 ... ] Something with list
我基本上只是阅读了各种工具的帮助文本,但是否有指南列表或其他内容?例如,我是用方括号还是圆括号?如何使用空格?如果参数是一个列表呢?谢谢!
我使用CSS形式符号表示。
Component values may be arranged into property values as follows:
Several juxtaposed words mean that all of them must occur, in the given order.
A bar (|) separates two or more alternatives: exactly one of them must occur.
A double bar (||) separates two or more options: one or more of them must occur, in any order.
A double ampersand (&&) separates two or more components, all of which must occur, in any order.
Brackets ([ ]) are for grouping.
Juxtaposition is stronger than the double ampersand, the double ampersand is stronger than the double bar, and the double bar is stronger than the bar. Thus, the following lines are equivalent:
a b | c || d && e f
[ a b ] | [ c || [ d && [ e f ]]]
Every type, keyword, or bracketed group may be followed by one of the following modifiers:
An asterisk (*) indicates that the preceding type, word, or group occurs zero or more times.
A plus (+) indicates that the preceding type, word, or group occurs one or more times.
A question mark (?) indicates that the preceding type, word, or group is optional.
A pair of numbers in curly braces ({A,B}) indicates that the preceding type, word, or group occurs at least A and at most B times.
如果您需要示例,请参阅MDN上的正式定义部分;这里有一个字体:https://developer.mozilla.org/en-US/docs/Web/CSS/font#formal_syntax。
下面是我自己Pandoc小抄中的一个简单例子:
$ pandoc <input_file>.md --from [markdown|commonmark_x][-smart]? --to html --standalone --table-of-contents? --number-sections? [--css <style_sheet>.css]? --output <output_file>.html
通常,你的帮助输出应该包括:
Description of what the app does
Usage syntax, which:
Uses [options] to indicate where the options go
arg_name for a required, singular arg
[arg_name] for an optional, singular arg
arg_name... for a required arg of which there can be many (this is rare)
[arg_name...] for an arg for which any number can be supplied
note that arg_name should be a descriptive, short name, in lower, snake case
A nicely-formatted list of options, each:
having a short description
showing the default value, if there is one
showing the possible values, if that applies
Note that if an option can accept a short form (e.g. -l) or a long form (e.g. --list), include them together on the same line, as their descriptions will be the same
Brief indicator of the location of config files or environment variables that might be the source of command line arguments, e.g. GREP_OPTS
If there is a man page, indicate as such, otherwise, a brief indicator of where more detailed help can be found
进一步注意,同时接受-h和——help来触发这条消息是一种很好的形式,如果用户弄乱了命令行语法,例如遗漏了一个必需的参数,你应该显示这条消息。