summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThe Bundler Bot <bot@bundler.io>2018-06-27 15:29:51 +0000
committerColby Swandale <me@colby.fyi>2018-10-05 16:15:43 +1000
commit7671d89e2cb2d30f9a583b7c417fde7eb48d8697 (patch)
tree6c8330de27f81b5911ca5f1d3d383ab17b5c6b49
parenta5867b633a9c7e5755266618178e6ee25ce6aa16 (diff)
downloadbundler-7671d89e2cb2d30f9a583b7c417fde7eb48d8697.tar.gz
Auto merge of #6572 - agrim123:agr-bundle-list-options, r=hsbt
[bundle list] add `--without-group` and `--only-group` Listing gems according to groups, either excluding a particular or from a specific group. Usage: ```bash bundle list --without-group dev ``` ```bash bundle list --only-group dev ``` Addresses #6564 (cherry picked from commit 25bcb86eb3e0fe8dd18a7b42728d4eda9554beec)
-rw-r--r--lib/bundler/cli.rb2
-rw-r--r--lib/bundler/cli/list.rb45
-rw-r--r--man/bundle-list.ronn18
-rw-r--r--spec/commands/list_spec.rb53
4 files changed, 110 insertions, 8 deletions
diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb
index 8ebef850fc..19d605f971 100644
--- a/lib/bundler/cli.rb
+++ b/lib/bundler/cli.rb
@@ -287,6 +287,8 @@ module Bundler
if Bundler.feature_flag.list_command?
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 "paths", :type => :boolean, :banner => "print the path to each gem in the bundle"
def list
require "bundler/cli/list"
diff --git a/lib/bundler/cli/list.rb b/lib/bundler/cli/list.rb
index c92f05df07..d1799196e7 100644
--- a/lib/bundler/cli/list.rb
+++ b/lib/bundler/cli/list.rb
@@ -7,19 +7,52 @@ module Bundler
end
def run
- specs = Bundler.load.specs.reject {|s| s.name == "bundler" }.sort_by(&:name)
+ raise InvalidOption, "The `--only-group` and `--without-group` options cannot be used together" if @options["only-group"] && @options["without-group"]
+
+ 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"]
+ filtered_specs_by_groups
+ else
+ Bundler.load.specs
+ end.reject {|s| s.name == "bundler" }.sort_by(&:name)
+
+ return Bundler.ui.info "No gems in the Gemfile" if specs.empty?
- raise InvalidOption, "The `--name-only` and `--paths` options cannot be used together" if @options["name-only"] && @options["paths"]
return specs.each {|s| Bundler.ui.info s.name } if @options["name-only"]
return specs.each {|s| Bundler.ui.info s.full_gem_path } if @options["paths"]
- return Bundler.ui.info "No gems in the Gemfile" if specs.empty?
Bundler.ui.info "Gems included by the bundle:"
- specs.each do |s|
- Bundler.ui.info " * #{s.name} (#{s.version}#{s.git_version})"
- end
+
+ specs.each {|s| Bundler.ui.info " * #{s.name} (#{s.version}#{s.git_version})" }
Bundler.ui.info "Use `bundle info` to print more detailed information about a gem"
end
+
+ 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)
+ end
+
+ def filtered_specs_by_groups
+ definition = Bundler.definition
+ groups = definition.groups
+
+ 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 }
+ else
+ groups
+ end.map(&:to_sym)
+
+ definition.specs_for(show_groups)
+ end
end
end
diff --git a/man/bundle-list.ronn b/man/bundle-list.ronn
index b7a9d3f786..120cf5e307 100644
--- a/man/bundle-list.ronn
+++ b/man/bundle-list.ronn
@@ -3,15 +3,31 @@ bundle-list(1) -- List all the gems in the bundle
## SYNOPSIS
-`bundle list` [--name-only]
+`bundle list` [--name-only] [--paths] [--without-group=GROUP] [--only-group=GROUP]
## DESCRIPTION
Prints a list of all the gems in the bundle including their version.
+Example:
+
+bundle list --name-only
+
+bundle list --paths
+
+bundle list --without-group test
+
+bundle list --only-group dev
+
+bundle list --only-group dev --paths
+
## OPTIONS
* `--name-only`:
Print only the name of each gem.
* `--paths`:
Print the path to each gem in the bundle.
+* `--without-group`:
+ Print all gems expect from a group.
+* `--only-group`:
+ Print gems from a particular group.
diff --git a/spec/commands/list_spec.rb b/spec/commands/list_spec.rb
index 4ebe934ca7..5305176c65 100644
--- a/spec/commands/list_spec.rb
+++ b/spec/commands/list_spec.rb
@@ -4,21 +4,72 @@ RSpec.describe "bundle list", :bundler => "2" do
before do
install_gemfile <<-G
source "file://#{gem_repo1}"
+
gem "rack"
+ gem "rspec", :group => [:test]
G
end
context "with name-only and paths option" do
it "raises an error" do
bundle "list --name-only --paths"
+
expect(out).to eq "The `--name-only` and `--paths` options cannot be used together"
end
end
+ context "with without-group and only-group option" do
+ it "raises an error" do
+ bundle "list --without-group dev --only-group test"
+
+ expect(out).to eq "The `--only-group` and `--without-group` options cannot be used together"
+ end
+ end
+
+ describe "with without-group option" do
+ context "when group is present" do
+ it "prints the gems not in the specified group" do
+ bundle! "list --without-group test"
+
+ expect(out).to include(" * rack (1.0.0)")
+ expect(out).not_to include(" * rspec (1.2.7)")
+ end
+ end
+
+ context "when group is not found" do
+ it "raises an error" do
+ bundle "list --without-group random"
+
+ expect(out).to eq "`random` group could not be found."
+ end
+ end
+ end
+
+ describe "with only-group option" do
+ context "when group is present" do
+ it "prints the gems in the specified group" do
+ bundle! "list --only-group default"
+
+ expect(out).to include(" * rack (1.0.0)")
+ expect(out).not_to include(" * rspec (1.2.7)")
+ end
+ end
+
+ context "when group is not found" do
+ it "raises an error" do
+ bundle "list --only-group random"
+
+ expect(out).to eq "`random` group could not be found."
+ end
+ end
+ end
+
context "with name-only option" do
it "prints only the name of the gems in the bundle" do
bundle "list --name-only"
- expect(out).to eq "rack"
+
+ expect(out).to include("rack")
+ expect(out).to include("rspec")
end
end