diff options
author | Andre Arko <andre@arko.net> | 2013-02-14 23:51:45 -0800 |
---|---|---|
committer | Andre Arko <andre@arko.net> | 2013-02-17 00:24:14 -0800 |
commit | 7ede3d80ffeb1a919d583f8a36db66e89b414ae3 (patch) | |
tree | be9e8924686eb6114f21ace45e1d3e1ca319a015 /lib | |
parent | c0620ef0d05f6f6bfe9208ccaccac92f2558cee9 (diff) | |
download | bundler-7ede3d80ffeb1a919d583f8a36db66e89b414ae3.tar.gz |
Merge pull request #1983 from takkanm/add-grep-option
Add: grep option for bundle open
Conflicts:
lib/bundler/cli.rb
lib/bundler/ui.rb
Diffstat (limited to 'lib')
-rw-r--r-- | lib/bundler/cli.rb | 43 | ||||
-rw-r--r-- | lib/bundler/ui.rb | 7 |
2 files changed, 38 insertions, 12 deletions
diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb index ce96772e..d863e0a1 100644 --- a/lib/bundler/cli.rb +++ b/lib/bundler/cli.rb @@ -296,7 +296,7 @@ module Bundler Bundler.definition(true) else # cycle through the requested gems, just to make sure they exist - gems.each{ |n| gem_dependency_with_name(n) } + gems.map{|g| select_spec(g) }.map(&:name) Bundler.definition(:gems => gems, :sources => sources) end @@ -580,7 +580,7 @@ module Bundler def open(name) editor = [ENV['BUNDLER_EDITOR'], ENV['VISUAL'], ENV['EDITOR']].find{|e| !e.nil? && !e.empty? } if editor - gem_path = locate_gem(name) + return unless gem_path = locate_gem(name, true) Dir.chdir(gem_path) do command = "#{editor} #{gem_path}" success = system(command) @@ -801,23 +801,38 @@ module Bundler end end - def have_groff? - !(`which groff` rescue '').empty? - end + def locate_gem(name, regexp_match = false) + return unless spec = select_spec(name, regexp_match) - def locate_gem(name) - spec = Bundler.load.specs.find{|s| s.name == name } - raise GemNotFound, not_found_message(name, Bundler.load.specs) unless spec if spec.name == 'bundler' return File.expand_path('../../../', __FILE__) end spec.full_gem_path end - def gem_dependency_with_name(name) - dep = Bundler.load.dependencies.find{|d| d.name == name } - raise GemNotFound, not_found_message(name, Bundler.load.dependencies) unless dep - dep + def select_spec(name, regexp_match = false) + specs = [] + regexp_name = Regexp.new(name) + + Bundler.load.specs.each do |spec| + return spec if spec.name == name + specs << spec if regexp_match && spec.name =~ regexp_name + end + + case specs.count + when 0 + raise GemNotFound, not_found_message(name, Bundler.load.dependencies) + when 1 + specs[0] + else + specs.each_with_index do |spec, index| + Bundler.ui.info "#{index.succ} : #{spec.name}", true + end + Bundler.ui.info '0 : - exit -', true + + input = Bundler.ui.ask('> ') + (num = input.to_i) > 0 ? specs[num - 1] : nil + end end def not_found_message(missing_gem_name, alternatives) @@ -831,6 +846,10 @@ module Bundler message end + def have_groff? + !(`which groff` rescue '').empty? + end + def pager_system pager = ENV['PAGER'] || ENV['MANPAGER'] pager ||= 'less -R' if !(`which less` rescue '').empty? diff --git a/lib/bundler/ui.rb b/lib/bundler/ui.rb index 9dd0db71..786c49ee 100644 --- a/lib/bundler/ui.rb +++ b/lib/bundler/ui.rb @@ -24,6 +24,9 @@ module Bundler false end + def ask(message) + end + class Shell < UI attr_reader :quiet attr_writer :shell @@ -75,6 +78,10 @@ module Bundler tell_me(msg, nil, newline) if debug? end + def ask(msg) + @shell.ask(msg) + end + def trace(e, newline = nil) msg = ["#{e.class}: #{e.message}", *e.backtrace].join("\n") if debug? |