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

add --paths option to bundle list command. #6177

Merged
merged 3 commits into from Jan 8, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/bundler/cli.rb
Expand Up @@ -285,6 +285,7 @@ def show(gem_name = nil)
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 "paths", :type => :boolean, :banner => "print the path to each gem in the bundle"
Copy link
Member

Choose a reason for hiding this comment

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

what happens if you pass bundle list --paths --name-only?

Copy link
Member Author

Choose a reason for hiding this comment

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

Bundler will just print the same output as bundler list --name-only

Copy link
Member

Choose a reason for hiding this comment

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

we probably should make it an error if both are passed, then

def list
require "bundler/cli/list"
List.new(options).run
Expand Down
3 changes: 3 additions & 0 deletions lib/bundler/cli/list.rb
Expand Up @@ -8,7 +8,10 @@ def initialize(options)

def run
specs = Bundler.load.specs.reject {|s| s.name == "bundler" }.sort_by(&:name)

return Bundler.ui.error "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:"
Expand Down
2 changes: 2 additions & 0 deletions man/bundle-list.ronn
Expand Up @@ -13,3 +13,5 @@ Prints a list of all the gems in the bundle including their version.

* `--name-only`:
Print only the name of each gem.
* `--paths`:
Print the path to each gem in the bundle.
40 changes: 40 additions & 0 deletions spec/commands/list_spec.rb
Expand Up @@ -8,13 +8,53 @@
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 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 "with paths option" do
before do
build_repo2 do
build_gem "bar"
end

build_git "git_test", "1.0.0", :path => lib_path("git_test")

build_lib("gemspec_test", :path => tmp.join("gemspec_test")) do |s|
s.write("Gemfile", "source :rubygems\ngemspec")
s.add_dependency "bar", "=1.0.0"
end

install_gemfile <<-G
source "file://#{gem_repo2}"
gem "rack"
gem "rails"
gem "git_test", :git => "#{lib_path("git_test")}"
gemspec :path => "#{tmp.join("gemspec_test")}"
G

bundle! "install"
end

it "prints the path of each gem in the bundle" do
bundle "list --paths"
expect(out).to match(%r{.*\/rails\-2\.3\.2})
expect(out).to match(%r{.*\/rack\-1\.2})
expect(out).to match(%r{.*\/git_test\-\w})
expect(out).to match(%r{.*\/gemspec_test})
end
end

context "when no gems are in the gemfile" do
before do
install_gemfile <<-G
Expand Down