summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThe Bundler Bot <bot@bundler.io>2017-04-07 03:35:05 +0000
committerThe Bundler Bot <bot@bundler.io>2017-04-07 03:35:05 +0000
commit32fb8327328789bdc911dccda4a59e99956c558c (patch)
tree92e0de674fdd0a70d844fd268ad7f2c881a67d5c
parent7358d857d32ce07c79b874e60441b971ff4c0f24 (diff)
parent1754e5019fe7f97db6d24f11bba8768d1dca7772 (diff)
downloadbundler-32fb8327328789bdc911dccda4a59e99956c558c.tar.gz
Auto merge of #5456 - Shekharrajak:5452_bundle_inject_options, r=colby-swandale
`bundle inject` with source and group options Fixes https://github.com/bundler/bundler/issues/5452 Eg ``` $ bundle inject "bootstrap" ">0" --source=https://rubygems.org --group=development Fetching gem metadata from https://rubygems.org/............ Fetching version metadata from https://rubygems.org/.. Fetching dependency metadata from https://rubygems.org/. Fetching gem metadata from https://rubygems.org/............. Fetching version metadata from https://rubygems.org/.. Fetching dependency metadata from https://rubygems.org/. Added to Gemfile: bootstrap (> 0), group => [:development], :source => 'https://rubygems.org' ``` In GemFile ``` gem 'bootstrap', '> 0', :group => [:development], :source => 'https://rubygems.org' ``` ### Multiple group : ``` $ dbundle inject "bootstrap" ">0" --source=https://rubygems.org --group=development,production Fetching gem metadata from https://rubygems.org/............ Added to Gemfile: gem 'bootstrap', '> 0', :group => [:development, :production], :source => 'https://rubygems.org' ``` In gemfile ``` # Added at 2017-03-24 11:40:51 +0530 by shekharrajak: gem 'bootstrap', '> 0', :group => [:development, :production], :source => 'https://rubygems.org' ```
-rw-r--r--lib/bundler/cli.rb6
-rw-r--r--lib/bundler/cli/inject.rb10
-rw-r--r--lib/bundler/injector.rb9
-rw-r--r--spec/commands/inject_spec.rb25
4 files changed, 46 insertions, 4 deletions
diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb
index 7c8a1a0fc6..61c5427c90 100644
--- a/lib/bundler/cli.rb
+++ b/lib/bundler/cli.rb
@@ -474,10 +474,14 @@ module Bundler
end
desc "inject GEM VERSION", "Add the named gem, with version requirements, to the resolved Gemfile"
+ method_option "source", :type => :string, :banner =>
+ "Install gem from the given source"
+ method_option "group", :type => :string, :banner =>
+ "Install gem into a bundler group"
def inject(name, version)
SharedHelpers.major_deprecation "The `inject` command has been replaced by the `add` command"
require "bundler/cli/inject"
- Inject.new(options, name, version).run
+ Inject.new(options.dup, name, version).run
end
desc "lock", "Creates a lockfile without installing"
diff --git a/lib/bundler/cli/inject.rb b/lib/bundler/cli/inject.rb
index cf35e4985b..b17292643f 100644
--- a/lib/bundler/cli/inject.rb
+++ b/lib/bundler/cli/inject.rb
@@ -6,7 +6,7 @@ module Bundler
@options = options
@name = name
@version = version || last_version_number
- @group = options[:group]
+ @group = options[:group].split(",") unless options[:group].nil?
@source = options[:source]
@gems = []
end
@@ -31,7 +31,13 @@ module Bundler
if added.any?
Bundler.ui.confirm "Added to Gemfile:"
- Bundler.ui.confirm added.map {|g| " #{g}" }.join("\n")
+ Bundler.ui.confirm(added.map do |d|
+ name = "'#{d.name}'"
+ requirement = ", '#{d.requirement}'"
+ group = ", :group => #{d.groups.inspect}" if d.groups != Array(:default)
+ source = ", :source => '#{d.source}'" unless d.source.nil?
+ %(gem #{name}#{requirement}#{group}#{source})
+ end.join("\n"))
else
Bundler.ui.confirm "All gems were already present in the Gemfile"
end
diff --git a/lib/bundler/injector.rb b/lib/bundler/injector.rb
index 787d95fd9c..7c78486dac 100644
--- a/lib/bundler/injector.rb
+++ b/lib/bundler/injector.rb
@@ -51,7 +51,14 @@ module Bundler
@new_deps.map do |d|
name = "'#{d.name}'"
requirement = ", '#{d.requirement}'"
- group = ", :group => #{d.groups.inspect}" if d.groups != Array(:default)
+ if d.groups != Array(:default)
+ group =
+ if d.groups.size == 1
+ ", :group => #{d.groups.inspect}"
+ else
+ ", :groups => #{d.groups.inspect}"
+ end
+ end
source = ", :source => '#{d.source}'" unless d.source.nil?
%(gem #{name}#{requirement}#{group}#{source})
end.join("\n")
diff --git a/spec/commands/inject_spec.rb b/spec/commands/inject_spec.rb
index dd5e22498b..5c711b32a0 100644
--- a/spec/commands/inject_spec.rb
+++ b/spec/commands/inject_spec.rb
@@ -52,6 +52,31 @@ Usage: "bundle inject GEM VERSION"
end
end
+ context "with source option" do
+ it "add gem with source option in gemfile" do
+ bundle "inject 'foo' '>0' --source file://#{gem_repo1}"
+ gemfile = bundled_app("Gemfile").read
+ str = "gem 'foo', '> 0', :source => 'file://#{gem_repo1}'"
+ expect(gemfile).to include str
+ end
+ end
+
+ context "with group option" do
+ it "add gem with group option in gemfile" do
+ bundle "inject 'rack-obama' '>0' --group=development"
+ gemfile = bundled_app("Gemfile").read
+ str = "gem 'rack-obama', '> 0', :group => [:development]"
+ expect(gemfile).to include str
+ end
+
+ it "add gem with multiple groups in gemfile" do
+ bundle "inject 'rack-obama' '>0' --group=development,test"
+ gemfile = bundled_app("Gemfile").read
+ str = "gem 'rack-obama', '> 0', :groups => [:development, :test]"
+ expect(gemfile).to include str
+ end
+ end
+
context "when frozen" do
before do
bundle "install"