Skip to content
This repository has been archived by the owner on Apr 14, 2021. It is now read-only.

Multiple without-group support for bundler list #6939

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/bundler/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ def show(gem_name = nil)
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 expect from a group"
method_option "without-group", :type => :string, :banner => "print all gems expect from 1 or multiple groups"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how does a given set of groups sound instead?

method_option "paths", :type => :boolean, :banner => "print the path to each gem in the bundle"
def list
require "bundler/cli/list"
Expand Down
15 changes: 12 additions & 3 deletions lib/bundler/cli/list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,16 @@ def run

private

def without_groups
@without_groups ||= @options["without-group"].split(/\s*,\s*/)
end

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)
if @options["without-group"]
without_groups.each do |without_group|
raise InvalidOption, "`#{without_group}` group could not be found." unless groups.include?(without_group.to_sym)
end
end

raise InvalidOption, "`#{@options["only-group"]}` group could not be found." if @options["only-group"] && !groups.include?(@options["only-group"].to_sym)
end
Expand All @@ -45,13 +53,14 @@ def filtered_specs_by_groups

show_groups =
if @options["without-group"]
groups.reject {|g| g == @options["without-group"].to_sym }
without_groups.inject(groups) do |memo, without_group|
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what memo means here, can you clarify please?

memo.reject {|g| g == without_group.to_sym }
end
elsif @options["only-group"]
groups.select {|g| g == @options["only-group"].to_sym }
else
groups
end.map(&:to_sym)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't remove the spacing. It helps with readability.

definition.specs_for(show_groups)
end
end
Expand Down
4 changes: 2 additions & 2 deletions man/bundle-list.ronn
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ bundle list --name-only

bundle list --paths

bundle list --without-group test
bundle list --without-group test[,other_group,...]

bundle list --only-group dev

Expand All @@ -28,6 +28,6 @@ bundle list --only-group dev --paths
* `--paths`:
Print the path to each gem in the bundle.
* `--without-group`:
Print all gems expect from a group.
Print all gems expect from 1 or multiple groups.
* `--only-group`:
Print gems from a particular group.
24 changes: 24 additions & 0 deletions spec/commands/list_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,30 @@
expect(out).to eq "`random` group could not be found."
end
end

describe "with multiple without-groups" do
before do
install_gemfile <<-G
source "file://#{gem_repo1}"

gem "rack"
gem "rspec", :group => [:test]
gem "rails", :group => [:development]
gem "git_test", group: %i[test development]
gem "rspec_in_context", group: %i[production development]
G
end

it "removes all the needed gems" do
bundle! 'list --without-group "development, test"'

expect(out).to include(/rack/)
expect(out).to include(/rspec_in_context/)
expect(out).not_to include(/rails/)
expect(out).not_to include(/git_test/)
expect(out).not_to include(/rspec/)
end
end
end

describe "with only-group option" do
Expand Down