diff options
author | The Bundler Bot <bot@bundler.io> | 2017-02-03 01:37:10 +0000 |
---|---|---|
committer | Samuel Giddins <segiddins@segiddins.me> | 2017-02-12 15:28:51 -0800 |
commit | 45eccc8e91b8903d4ad28e44028726b25bfbb503 (patch) | |
tree | 66378ebcf62ca49e03851dada15acda43cbc0886 | |
parent | 40024a69b224b11132828d07dc43294de127e590 (diff) | |
download | bundler-45eccc8e91b8903d4ad28e44028726b25bfbb503.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"
```
(cherry picked from commit ec5cab34d3b12467433ca1a1eafc460e42834084)
-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 eb9362a500..e29f74db73 100644 --- a/lib/bundler/cli.rb +++ b/lib/bundler/cli.rb @@ -460,11 +460,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 d0112915ca..aae17222f5 100644 --- a/spec/commands/inject_spec.rb +++ b/spec/commands/inject_spec.rb @@ -42,6 +42,16 @@ 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" |