bash - `-s --` 标志对 npm 有什么作用?
问题描述
我刚刚观看了Kent C. Dodds 的视频,他在其中解释了他的.bash_profile
.
yarn
他对and使用以下别名npm
:
## npm aliases
alias ni="npm install";
alias nrs="npm run start -s --";
alias nrb="npm run build -s --";
alias nrd="npm run dev -s --";
alias nrt="npm run test -s --";
alias nrtw="npm run test:watch -s --";
alias nrv="npm run validate -s --";
alias rmn="rm -rf node_modules";
alias flush-npm="rm -rf node_modules && npm i && say NPM is done";
alias nicache="npm install --prefer-offline";
alias nioff="npm install --offline";
## yarn aliases
alias yar="yarn run";
alias yas="yarn run start -s --";
alias yab="yarn run build -s --";
alias yat="yarn run test -s --";
alias yav="yarn run validate -s --";
alias yoff="yarn add --offline";
alias ypm="echo \"Installing deps without lockfile and ignoring engines\" && yarn install --no-lockfile --ignore-engines"
我想知道,-s --
国旗有什么作用?肯特没有在视频中解释它,我在旗帜上找不到任何信息。
解决方案
选项-s
使得yarn
不要在标准输出上输出任何东西,即。让它沉默。
来自posix 实用程序约定--
,在命令行 linux 工具中非常常见:
Guideline 10:
The first -- argument that is not an option-argument should be accepted as a delimiter indicating the end of options. Any following arguments should be treated as operands, even if they begin with the '-' character.
所以:
> printf "%s" -n
-n
一切OK,它会打印-n
。但:
> printf -n
bash: printf: -n: invalid option
printf: usage: printf [-v var] format [arguments]
允许通过-n
,即。选项-
以前导作为 printf 的第一个参数开始,可以使用--
:
> printf -- -n
-n
所以:
alias yas="yarn run start -s";
yas -package
将通过纱线抛出未知选项,因为它会尝试解析-p
为选项。正在做:
alias yas="yarn run start -s --";
yas -package
将抛出未知包,yarn
因为没有名为 的包-package
。通过使用--
作者有效地阻止用户(他自己)将任何附加选项传递给纱线,因为所有以下参数将仅被解释为包名称。
推荐阅读
- arrays - 如何在 React 中映射嵌套数据对象?
- c# - 使用邮递员在 ASP.NET Framework 中发布问题
- powershell - New-ADUser 其他属性 服务器不愿意处理请求
- perl - YAML 与自定义方法合并
- r - 垂直合并2个变量R tidyverse
- google-apps-script - 使用 Google Analytics 跟踪 shpreadsheet+appscript 作为 UI 和 BE 而不是网站的印象
- google-sheets - 为什么这个查询函数返回不正确的结果?
- c# - Azure BlobBaseClient.OpenReadAsync() 导致:System.InvalidOperationException:响应内容长度不匹配:写入的字节太少(...)
- python - 以长格式保存具有不同级别名称的多索引列 Pandas 为 excel 格式
- javascript - 在 Laravel-8 中使用 ajax 请求和 sweet alert2 删除项目