summaryrefslogtreecommitdiff
path: root/lib/bundler/cli/list.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/bundler/cli/list.rb')
-rw-r--r--lib/bundler/cli/list.rb20
1 files changed, 11 insertions, 9 deletions
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)