diff options
author | The Bundler Bot <bot@bundler.io> | 2017-02-03 01:37:10 +0000 |
---|---|---|
committer | The Bundler Bot <bot@bundler.io> | 2017-02-03 01:37:10 +0000 |
commit | ec5cab34d3b12467433ca1a1eafc460e42834084 (patch) | |
tree | c26c9d8cfa60f3ca6507a390087a30d19d71da81 | |
parent | d9d699c174a06da8052bc7da0d5ba64438968653 (diff) | |
parent | a3ff7e2c0d21a0a96e68ee72d86e7f6a371401fe (diff) | |
download | bundler-ec5cab34d3b12467433ca1a1eafc460e42834084.tar.gz |
Auto merge of #5389 - Shekharrajak:5384_inject_usage, r=segiddins
Show inject usage when args are passed incorrectly
Closes #5384
Now it shows the error :
```
$ bundle inject "gem_name" 1 "v"
ERROR: "bundle inject" was called with arguments ["gem_name", "1", "v"]
Usage: "bundle inject GEM VERSION"
$ bundle inject "gem_name" "v" 1
ERROR: "bundle inject" was called with arguments ["gem_name", "v", "1"]
Usage: "bundle inject GEM VERSION"
```
-rw-r--r-- | lib/bundler/cli.rb | 6 | ||||
-rw-r--r-- | lib/bundler/cli/inject.rb | 6 | ||||
-rw-r--r-- | spec/commands/inject_spec.rb | 10 |
3 files changed, 17 insertions, 5 deletions
diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb index a70d66f200..d6e811b41a 100644 --- a/lib/bundler/cli.rb +++ b/lib/bundler/cli.rb @@ -461,11 +461,11 @@ module Bundler Platform.new(options).run end - desc "inject GEM VERSION ...", "Add the named gem(s), with version requirements, to the resolved Gemfile" - def inject(name, version, *gems) + desc "inject GEM VERSION", "Add the named gem, with version requirements, to the resolved Gemfile" + 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, gems).run + Inject.new(options, 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 9d1d08120a..cf35e4985b 100644 --- a/lib/bundler/cli/inject.rb +++ b/lib/bundler/cli/inject.rb @@ -2,13 +2,13 @@ module Bundler class CLI::Inject attr_reader :options, :name, :version, :group, :source, :gems - def initialize(options, name, version, gems) + def initialize(options, name, version) @options = options @name = name @version = version || last_version_number @group = options[:group] @source = options[:source] - @gems = gems + @gems = [] end def run @@ -18,6 +18,8 @@ module Bundler # Build an array of Dependency objects out of the arguments deps = [] + # when `inject` support addition of more than one gem, then this loop will + # help. Currently this loop is running once. gems.each_slice(4) do |gem_name, gem_version, gem_group, gem_source| ops = Gem::Requirement::OPS.map {|key, _val| key } has_op = ops.any? {|op| gem_version.start_with? op } diff --git a/spec/commands/inject_spec.rb b/spec/commands/inject_spec.rb index 96209bda7b..dd5e22498b 100644 --- a/spec/commands/inject_spec.rb +++ b/spec/commands/inject_spec.rb @@ -42,6 +42,16 @@ RSpec.describe "bundle inject" do end end + context "incorrect arguments" do + it "fails when more than 2 arguments are passed" do + bundle "inject gem_name 1 v" + expect(out).to eq(<<-E.strip) +ERROR: "bundle inject" was called with arguments ["gem_name", "1", "v"] +Usage: "bundle inject GEM VERSION" + E + end + end + context "when frozen" do before do bundle "install" |