summaryrefslogtreecommitdiff
path: root/lib/bundler
diff options
context:
space:
mode:
authorfatkodima <fatkodima123@gmail.com>2019-10-31 15:01:39 +0200
committerfatkodima <fatkodima123@gmail.com>2019-11-01 15:56:41 +0200
commit95d7e474e454c79c7b6d73d96e36547e2f1f0e35 (patch)
tree3ef977a1728501b82a29407bd0bf66ebafae2c37 /lib/bundler
parent49f585ca9e5ecf2f0cf5529e1b320ce07d443de9 (diff)
downloadbundler-95d7e474e454c79c7b6d73d96e36547e2f1f0e35.tar.gz
Support multiple groups for --without-group and --only-group options in bundler list command
Diffstat (limited to 'lib/bundler')
-rw-r--r--lib/bundler/cli.rb4
-rw-r--r--lib/bundler/cli/list.rb20
2 files changed, 13 insertions, 11 deletions
diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb
index bacbb8dbde..4717c0e9eb 100644
--- a/lib/bundler/cli.rb
+++ b/lib/bundler/cli.rb
@@ -345,8 +345,8 @@ module Bundler
desc "list", "List all gems in the bundle"
method_option "name-only", :type => :boolean, :banner => "print only the gem names"
- method_option "only-group", :type => :string, :banner => "print gems from a particular group"
- method_option "without-group", :type => :string, :banner => "print all gems except from a group"
+ method_option "only-group", :type => :array, :default => [], :banner => "print gems from a given set of groups"
+ method_option "without-group", :type => :array, :default => [], :banner => "print all gems except from a given set of groups"
method_option "paths", :type => :boolean, :banner => "print the path to each gem in the bundle"
def list
require_relative "cli/list"
diff --git a/lib/bundler/cli/list.rb b/lib/bundler/cli/list.rb
index d1799196e7..c172e8d182 100644
--- a/lib/bundler/cli/list.rb
+++ b/lib/bundler/cli/list.rb
@@ -4,14 +4,16 @@ module Bundler
class CLI::List
def initialize(options)
@options = options
+ @without_group = options["without-group"].map(&:to_sym)
+ @only_group = options["only-group"].map(&:to_sym)
end
def run
- raise InvalidOption, "The `--only-group` and `--without-group` options cannot be used together" if @options["only-group"] && @options["without-group"]
+ raise InvalidOption, "The `--only-group` and `--without-group` options cannot be used together" if @only_group.any? && @without_group.any?
raise InvalidOption, "The `--name-only` and `--paths` options cannot be used together" if @options["name-only"] && @options[:paths]
- specs = if @options["only-group"] || @options["without-group"]
+ specs = if @only_group.any? || @without_group.any?
filtered_specs_by_groups
else
Bundler.load.specs
@@ -32,9 +34,9 @@ module Bundler
private
def verify_group_exists(groups)
- raise InvalidOption, "`#{@options["without-group"]}` group could not be found." if @options["without-group"] && !groups.include?(@options["without-group"].to_sym)
-
- raise InvalidOption, "`#{@options["only-group"]}` group could not be found." if @options["only-group"] && !groups.include?(@options["only-group"].to_sym)
+ (@without_group + @only_group).each do |group|
+ raise InvalidOption, "`#{group}` group could not be found." unless groups.include?(group)
+ end
end
def filtered_specs_by_groups
@@ -44,10 +46,10 @@ module Bundler
verify_group_exists(groups)
show_groups =
- if @options["without-group"]
- groups.reject {|g| g == @options["without-group"].to_sym }
- elsif @options["only-group"]
- groups.select {|g| g == @options["only-group"].to_sym }
+ if @without_group.any?
+ groups.reject {|g| @without_group.include?(g) }
+ elsif @only_group.any?
+ groups.select {|g| @only_group.include?(g) }
else
groups
end.map(&:to_sym)