diff options
author | Jerome Dalbert <[email protected]> | 2024-10-16 19:17:55 -0700 |
---|---|---|
committer | git <[email protected]> | 2024-10-18 16:19:31 +0000 |
commit | fce5bbd6a7a20c4a559ade1205e3fdb0f5d003d0 (patch) | |
tree | a4f83d550222c4c5f84d6d04f60fefe44d048b43 | |
parent | 689f14e255593172abe31a7669b47b528e47214f (diff) |
[rubygems/rubygems] Add `bundle add --quiet` option
This option is similar to the `bundle install --quiet` option
https://github.com/rubygems/rubygems/commit/3bd773d827
-rw-r--r-- | lib/bundler/cli.rb | 1 | ||||
-rw-r--r-- | lib/bundler/cli/add.rb | 2 | ||||
-rw-r--r-- | lib/bundler/man/bundle-add.1 | 5 | ||||
-rw-r--r-- | lib/bundler/man/bundle-add.1.ronn | 5 | ||||
-rw-r--r-- | spec/bundler/commands/add_spec.rb | 32 |
5 files changed, 43 insertions, 2 deletions
diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb index 013ffcdeed..62ad52f426 100644 --- a/lib/bundler/cli.rb +++ b/lib/bundler/cli.rb @@ -353,6 +353,7 @@ module Bundler method_option "branch", type: :string method_option "ref", type: :string method_option "glob", type: :string, banner: "The location of a dependency's .gemspec, expanded within Ruby (single quotes recommended)" + method_option "quiet", type: :boolean, banner: "Only output warnings and errors." method_option "skip-install", type: :boolean, banner: "Adds gem to the Gemfile but does not install it" method_option "optimistic", type: :boolean, banner: "Adds optimistic declaration of version to gem" method_option "strict", type: :boolean, banner: "Adds strict declaration of version to gem" diff --git a/lib/bundler/cli/add.rb b/lib/bundler/cli/add.rb index 2b300e1783..12a681a816 100644 --- a/lib/bundler/cli/add.rb +++ b/lib/bundler/cli/add.rb @@ -12,6 +12,8 @@ module Bundler end def run + Bundler.ui.level = "warn" if options[:quiet] + validate_options! inject_dependencies perform_bundle_install unless options["skip-install"] diff --git a/lib/bundler/man/bundle-add.1 b/lib/bundler/man/bundle-add.1 index b0c6d2cc90..e477f77c5c 100644 --- a/lib/bundler/man/bundle-add.1 +++ b/lib/bundler/man/bundle-add.1 @@ -4,7 +4,7 @@ .SH "NAME" \fBbundle\-add\fR \- Add gem to the Gemfile and run bundle install .SH "SYNOPSIS" -\fBbundle add\fR \fIGEM_NAME\fR [\-\-group=GROUP] [\-\-version=VERSION] [\-\-source=SOURCE] [\-\-path=PATH] [\-\-git=GIT|\-\-github=GITHUB] [\-\-branch=BRANCH] [\-\-ref=REF] [\-\-skip\-install] [\-\-strict|\-\-optimistic] +\fBbundle add\fR \fIGEM_NAME\fR [\-\-group=GROUP] [\-\-version=VERSION] [\-\-source=SOURCE] [\-\-path=PATH] [\-\-git=GIT|\-\-github=GITHUB] [\-\-branch=BRANCH] [\-\-ref=REF] [\-\-quiet] [\-\-skip\-install] [\-\-strict|\-\-optimistic] .SH "DESCRIPTION" Adds the named gem to the [\fBGemfile(5)\fR][Gemfile(5)] and run \fBbundle install\fR\. \fBbundle install\fR can be avoided by using the flag \fB\-\-skip\-install\fR\. .SH "OPTIONS" @@ -36,6 +36,9 @@ Specify the git branch for the added gem\. \fB\-\-ref\fR Specify the git ref for the added gem\. .TP +\fB\-\-quiet\fR +Do not print progress information to the standard output\. +.TP \fB\-\-skip\-install\fR Adds the gem to the Gemfile but does not install it\. .TP diff --git a/lib/bundler/man/bundle-add.1.ronn b/lib/bundler/man/bundle-add.1.ronn index 8b38c7a248..ca09889200 100644 --- a/lib/bundler/man/bundle-add.1.ronn +++ b/lib/bundler/man/bundle-add.1.ronn @@ -5,7 +5,7 @@ bundle-add(1) -- Add gem to the Gemfile and run bundle install `bundle add` <GEM_NAME> [--group=GROUP] [--version=VERSION] [--source=SOURCE] [--path=PATH] [--git=GIT|--github=GITHUB] [--branch=BRANCH] [--ref=REF] - [--skip-install] [--strict|--optimistic] + [--quiet] [--skip-install] [--strict|--optimistic] ## DESCRIPTION @@ -41,6 +41,9 @@ Adds the named gem to the [`Gemfile(5)`][Gemfile(5)] and run `bundle install`. * `--ref`: Specify the git ref for the added gem. +* `--quiet`: + Do not print progress information to the standard output. + * `--skip-install`: Adds the gem to the Gemfile but does not install it. diff --git a/spec/bundler/commands/add_spec.rb b/spec/bundler/commands/add_spec.rb index 0a0d4c0046..e63b0b9658 100644 --- a/spec/bundler/commands/add_spec.rb +++ b/spec/bundler/commands/add_spec.rb @@ -284,6 +284,38 @@ RSpec.describe "bundle add" do end end + describe "with --quiet option" do + it "is quiet when there are no warnings" do + bundle "add 'foo' --quiet" + expect(out).to be_empty + expect(err).to be_empty + end + + it "still displays warning and errors" do + create_file("add_with_warning.rb", <<~RUBY) + require "#{lib_dir}/bundler" + require "#{lib_dir}/bundler/cli" + require "#{lib_dir}/bundler/cli/add" + + module RunWithWarning + def run + super + rescue + Bundler.ui.warn "This is a warning" + raise + end + end + + Bundler::CLI::Add.prepend(RunWithWarning) + RUBY + + bundle "add 'non-existing-gem' --quiet", raise_on_error: false, env: { "RUBYOPT" => "-r#{bundled_app("add_with_warning.rb")}" } + expect(out).to be_empty + expect(err).to include("Could not find gem 'non-existing-gem'") + expect(err).to include("This is a warning") + end + end + describe "with --strict option" do it "adds strict version" do bundle "add 'foo' --strict" |