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

Adding 'bundle grep PATTERN' for searching across gems / add bundle show --paths #1360

Closed
wants to merge 3 commits into from
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
14 changes: 14 additions & 0 deletions lib/bundler/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -266,11 +266,17 @@ def update(*gems)
Show lists the names and versions of all gems that are required by your Gemfile.
Calling show with [GEM] will list the exact location of that gem on your machine.
D
method_option "paths", :type => :boolean,
:banner => "List the paths of all gems that are required by your Gemfile."
def show(gem_name = nil)
Bundler.load.lock

if gem_name
Bundler.ui.info locate_gem(gem_name)
elsif options[:paths]
Bundler.load.specs.sort_by { |s| s.name }.each do |s|
Bundler.ui.info locate_gem(s.name)
end
else
Bundler.ui.info "Gems included by the bundle:"
Bundler.load.specs.sort_by { |s| s.name }.each do |s|
Expand Down Expand Up @@ -479,6 +485,14 @@ def console(group = nil)
IRB.start
end

desc "grep PATTERN", "..."
def grep(pattern)
Bundler.load.lock
Bundler.load.specs.sort_by { |s| s.name }.each do |s|
system("grep #{pattern.inspect} #{s.full_gem_path} --recursive --color=auto -o")
end
end

desc "version", "Prints the bundler's version information"
def version
Bundler.ui.info "Bundler version #{Bundler::VERSION}"
Expand Down
14 changes: 14 additions & 0 deletions spec/other/grep_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
require "spec_helper"

describe "bundle grep" do
it "prints grep output" do
install_gemfile <<-G
source "file://#{gem_repo1}"
gem "rake"
G

bundle "grep 'RAKE -- Ruby Make'"
out.should =~ /rake-0.8.7\/README:RAKE -- Ruby Make/i
end

end
13 changes: 13 additions & 0 deletions spec/other/show_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,19 @@
bundle "show missing"
out.should =~ /could not find gem 'missing'/i
end

it "prints path of all gems in bundle" do
bundle "show --paths"
out.should == %w(actionmailer-2.3.2 actionpack-2.3.2 activerecord-2.3.2
activeresource-2.3.2 activesupport-2.3.2 bundler-1.0.18
rails-2.3.2 rake-0.8.7).map { |name|
if name == 'bundler-1.0.18'
File.expand_path('../../../', __FILE__)
else
default_bundle_path('gems', name)
end.to_s
}.join("\n")
end
end

describe "bundle show with a git repo" do
Expand Down