命令行动词自变量的约定-a vs --arg [英] Conventions for command line verb arguments -a vs --arg

查看:70
本文介绍了命令行动词自变量的约定-a vs --arg的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚注意到一种用于动词样式命令参数的模式(在git和.NET的CommandLineParser lib中),并且想知道是否有人可以确认:

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

  • -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?)

只是好奇...我从来没有注意到git中的模式,而CommandLineParser文档非常薄,有些博客

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.

(为此...这种动词/ args样式甚至叫什么?我似乎在上面找不到很多东西

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

推荐答案

从维基百科: https://en.wikipedia.org/wiki/Command-line_interface

Unix中的选项约定类系统


在类Unix系统中,ASCII连字符减号开始选项;新的
(和GNU)约定是使用两个连字符,然后用一个单词(例如--create)
来标识选项的使用,而旧约定(以及
仍可作为常用选项)是使用一个
连字符,然后使用一个字母(例如-c);如果一个连字符后面跟有两个或
个字母,则可能意味着已指定两个选项,或者
意味着第二个及后续字母是一个参数(例如
文件名或日期)

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.

两个不带字母(-)的连字符减号可能会导致
表示不应将其余参数视为
选项,例如,如果文件名本身以
a连字符开头,或者如果要为内部命令使用其他参数(例如
sudo),则此选项很有用。有时在使用更具描述性的选项名称的情况下,有时还会使用双连字符减号来前缀 long
options。这是GNU软件的一个常见功能。通常使用getopt函数和程序以及
getopts命令来解析命令行选项。

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.

这篇关于命令行动词自变量的约定-a vs --arg的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆