-s标志对npm有什么作用?

时间:2019-02-12 10:08:47

标签: bash npm yarnpkg flags npm-scripts

我刚刚看过肯特·多德斯(Kent C. Dodds)的video,他在解释他的.bash_profile.

他为yarnnpm使用以下别名:

## 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 --标志的作用是什么?肯特(Kent)没有在视频中解释它,我在旗帜上找不到任何info

3 个答案:

答案 0 :(得分:3)

-s等效于--silent

--是通用的Unix约定,表示选项的结尾。之后,即使参数看起来像一个选项,也将被视为位置参数。

答案 1 :(得分:2)

选项-s使yarn在标准输出上不输出任何内容,即。将其静音。

--来自posix utility conventions,在命令行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

好的,它将打印-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的软件包。通过使用--,作者可以有效地阻止用户(他自己)将任何其他选项传递给yarn,因为以下所有参数仅被解释为程序包名称。

答案 2 :(得分:1)

这意味着命令选项的结尾。因此,双破折号后不能使用命令选项(例如from urllib.parse import urlencode from django.db.models import Max from taggit.models import Tag from wagtail.core.models import Page class HomePage(Page): # Note that the method signature should accept an optional request parameter as of Wagtail 2.2 def get_sitemap_urls(self, request=None): urls = super().get_sitemap_urls(request) # Get the page's URL, we will use that later. base_url = self.get_full_url(request) # Get the IDs of all the tags used on your `BlogPage`s. tag_ids = BlogPageTag.objects.values_list('tag_id', flat=True).distinct() # 1. Filter all the tags with the IDs fetched above. # 2. Annotate the query with the latest `last_published_at` of the associated pages. # Note the `home_` part in the string, this needs to be replaced by the name of the Django app your `BlogPageTag` model lives in. # 3. Only fetch the slug and lastmod (we don't need the full object). tags = Tag.objects\ .filter(pk__in=tag_ids)\ .annotate(lastmod=Max('home_blogpagetag_items__content_object__last_published_at'))\ .values('slug', 'lastmod') # Add sitemap entries for each tag. for tag in tags: urls.append({ 'location': '{}?{}'.format(base_url, urlencode({'tag': tag.slug})), 'lastmod': tag.lastmod, }) # Return the results. return urls )。但是,例如,您可以列出要通过命令处理的文件。

Explained here

-s选项本身短于-s,它禁用了日志输出。