运行 npm 命令时 - 会做什么? [英] What does -- do when running an npm command?

查看:46
本文介绍了运行 npm 命令时 - 会做什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,双破折号或两个连字符 -- 的用法如下:

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 option 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屋!

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