summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorColby Swandale <colby@taplaboratories.com>2017-08-05 11:33:30 +1000
committerColby Swandale <colby@taplaboratories.com>2017-08-10 18:25:43 +1000
commit5d22dbe1d49826cc5f7108d95e6981b1ed15c5d8 (patch)
treee6896f124988f680a031d0a34cfb6cfc8b712f3c
parent2c5dc254bbadd89e9a601c2f21976c733efdc1cb (diff)
downloadbundler-colby/bundler-list.tar.gz
add --name-only option to print only the name of each gemcolby/bundler-list
-rw-r--r--lib/bundler/cli.rb5
-rw-r--r--lib/bundler/cli/list.rb9
-rw-r--r--man/bundle-list.ronn9
-rw-r--r--spec/commands/list_spec.rb7
4 files changed, 24 insertions, 6 deletions
diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb
index 3cefc90970..3406a874ce 100644
--- a/lib/bundler/cli.rb
+++ b/lib/bundler/cli.rb
@@ -263,10 +263,11 @@ module Bundler
# TODO: 2.0 remove `bundle show`
if Bundler.feature_flag.list_command?
- desc "list", "list all gems in the bundle"
+ desc "list", "List all gems in the bundle"
+ method_option "name-only", :type => :boolean, :banner => "print only the gem names"
def list
require "bundler/cli/list"
- List.new.run
+ List.new(options).run
end
map %w[ls] => "list"
diff --git a/lib/bundler/cli/list.rb b/lib/bundler/cli/list.rb
index 623e2bc076..b5e7c1e650 100644
--- a/lib/bundler/cli/list.rb
+++ b/lib/bundler/cli/list.rb
@@ -2,12 +2,17 @@
module Bundler
class CLI::List
+ def initialize(options)
+ @options = options
+ end
+
def run
- specs = Bundler.load.specs.reject {|s| s.name == "bundler" }
+ specs = Bundler.load.specs.reject {|s| s.name == "bundler" }.sort_by(&:name)
+ return specs.each {|s| Bundler.ui.info s.name } if @options["name-only"]
return Bundler.ui.info "No gems in the Gemfile" if specs.empty?
Bundler.ui.info "Gems included by the bundle:"
- specs.sort_by(&:name).each do |s|
+ specs.each do |s|
Bundler.ui.info " * #{s.name} (#{s.version}#{s.git_version})"
end
diff --git a/man/bundle-list.ronn b/man/bundle-list.ronn
index 3a883bf5ff..79fcfff701 100644
--- a/man/bundle-list.ronn
+++ b/man/bundle-list.ronn
@@ -3,8 +3,13 @@ bundle-list(1) -- List all the gems in the bundle
## SYNOPSIS
-`bundle list`
+`bundle list` [--name-only]
## DESCRIPTION
-Prints a list of all the gems in the bundle including their version
+Prints a list of all the gems in the bundle including their version.
+
+## OPTIONS
+
+* `--name-only`:
+ Print only the name of each gem.
diff --git a/spec/commands/list_spec.rb b/spec/commands/list_spec.rb
index 850ca24dc2..0ea70f015c 100644
--- a/spec/commands/list_spec.rb
+++ b/spec/commands/list_spec.rb
@@ -8,6 +8,13 @@ RSpec.describe "bundle list", :bundler => "2" do
G
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"
+ end
+ end
+
context "when no gems are in the gemfile" do
before do
install_gemfile <<-G