Conventions for command line verb arguments -a vs --arg

家住魔仙堡 提交于 2019-12-24 03:27:43

问题


I've just noticed a pattern (in git and the CommandLineParser lib for .NET) for verb-style command arguments, and wondering if someone can confirm:

myprog dothis -a "someArg"

  • -a
  • --arg

What's the difference between the single-dash-prefix and the double-dash-prefix? Is the single dash prefix always for a single-letter argument specifier, where a double dash prefix always for a "long name" of the argument?

Is there a formal convention somewhere that drives this, or is it a generally accepted informal practice? (or am I just making something of nothing?)

Just curious... the I had never noticed the pattern in git and the CommandLineParser docs are pretty thin and some blog post or another implicated the convention.

(for that matter... what's this style of verb/args even called? I can't seem to find much of anything on it)


回答1:


From the wikipedia: https://en.wikipedia.org/wiki/Command-line_interface

Option conventions in Unix-like systems

In Unix-like systems, the ASCII hyphen-minus begins options; the new (and GNU) convention is to use two hyphens then a word (e.g. --create) to identify the option's use while the old convention (and still available as an option for frequently-used options) is to use one hyphen then one letter (e.g. -c); if one hyphen is followed by two or more letters it may mean two options are being specified, or it may mean the second and subsequent letters are a parameter (such as filename or date) for the first option.

Two hyphen-minus characters without following letters (--) may indicate that the remaining arguments should not be treated as options, which is useful for example if a file name itself begins with a hyphen, or if further arguments are meant for an inner command (e.g. sudo). Double hyphen-minuses are also sometimes used to prefix "long options" where more descriptive option names are used. This is a common feature of GNU software. The getopt function and program, and the getopts command are usually used for parsing command-line options.




回答2:


There is posix convention and getopt

But it's not always the case, e.g. java and find.

See also:

https://golang.org/pkg/flag/

http://docs.oracle.com/javase/8/javafx/api/javafx/application/Application.Parameters.html



来源:https://stackoverflow.com/questions/42183794/conventions-for-command-line-verb-arguments-a-vs-arg

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!