运行npm命令时会做什么? [英] What does -- do when running an npm command?
问题描述
例如,双破折号或两个连字符--
的用法如下:
As an example, double dash or two hyphens --
is used like so:
npm test -- --coverage
在没有双破折号的情况下运行npm
不会在覆盖模式下运行,因此似乎附加了后续标志,这是正确的吗?我找不到关于此的文档.
Running npm
without the double dash flag does not run in coverage mode so it seems to append subsequent flags, is this correct? I couldn't find the documentation on this.
推荐答案
--
本身作为参数已在所有UNIX命令中标准化:这意味着应将其他参数视为位置参数,而不是选项.请参阅 POSIX实用程序语法约定中的准则10.
--
as an argument on its own is standardized across all UNIX commands: It means that further arguments should be treated as positional arguments, not options. See Guideline 10 in POSIX Utility Syntax Conventions.
为了给您一个非基于NPM的示例,ls -- -l
将查找名为-l
的文件,因为--
指定了所有后续参数都是位置性的.
To give you a non-NPM-based example, ls -- -l
will look for a file named -l
, because the --
specified that all subsequent arguments are positional.
在这种情况下,这意味着--coverage
不是npm
本身的参数;大概,然后,它随后由test
子命令读取.对于遵循正确约定的工具,则没有必要,因为准则9指定所有选项都应在任何参数之前给出(因此,在这种情况下--coverage
应被视为参数,因为它位于参数test
之后);但是,由于NPM仅部分遵循了指南,这是可以预见的结果.
In this context, it means that --coverage
isn't an argument to npm
itself; presumably, then, it's subsequently read by the test
subcommand. For a tool that were following the conventions properly this wouldn't be necessary, because Guideline 9 specifies that all options shall be given before any arguments (thus that in this context --coverage
should be treated as an argument since it comes after the argument test
); however, inasmuch as NPM is only partially following the guidelines, this is a foreseeable result.
(长--option
样式的选项实际上实际上是一个GNU扩展,所以我们这里是对多种解析样式的误解;不幸的是,这就是生活).
(Long --option
-style options are actually a GNU extension as a whole, so what we have here is a mismash of multiple parsing styles; such is life, unfortunately).
这篇关于运行npm命令时会做什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!