diff --git a/Library/Homebrew/cmd/search.rb b/Library/Homebrew/cmd/search.rb index 2c2f95567d..3bf25a4b6b 100644 --- a/Library/Homebrew/cmd/search.rb +++ b/Library/Homebrew/cmd/search.rb @@ -9,7 +9,9 @@ module Homebrew SEARCH_ERROR_QUEUE = Queue.new def search - if ARGV.include? "--macports" + if ARGV.empty? + puts_columns Formula.full_names + elsif ARGV.include? "--macports" exec_browser "https://www.macports.org/ports.php?by=name&substr=#{ARGV.next}" elsif ARGV.include? "--fink" exec_browser "http://pdb.finkproject.org/pdb/browse.php?summary=#{ARGV.next}" @@ -25,8 +27,6 @@ module Homebrew query = ARGV.next rx = query_regexp(query) Descriptions.search(rx, :desc).print - elsif ARGV.empty? - puts_columns Formula.full_names elsif ARGV.first =~ HOMEBREW_TAP_FORMULA_REGEX query = ARGV.first user, repo, name = query.split("/", 3) @@ -44,39 +44,43 @@ module Homebrew local_results = search_formulae(rx) local_results_installed = local_results.select { |f| f.end_with? "(installed)" } puts_columns(local_results, local_results_installed) - - if !query.empty? && $stdout.tty? && msg = blacklisted?(query) - unless local_results.empty? - puts - puts "If you meant #{query.inspect} precisely:" - puts - end - puts msg - end - tap_results = search_taps(rx) puts_columns(tap_results) - count = local_results.length + tap_results.length - if count == 0 && !blacklisted?(query) - puts "No formula found for #{query.inspect}." - begin - GitHub.print_pull_requests_matching(query) - rescue GitHub::Error => e - SEARCH_ERROR_QUEUE << e + if $stdout.tty? + count = local_results.length + tap_results.length + + if msg = blacklisted?(query) + if count > 0 + puts + puts "If you meant #{query.inspect} precisely:" + puts + end + puts msg + elsif count == 0 + puts "No formula found for #{query.inspect}." + begin + GitHub.print_pull_requests_matching(query) + rescue GitHub::Error => e + SEARCH_ERROR_QUEUE << e + end end end end - metacharacters = %w[\\ | ( ) [ ] { } ^ $ * + ? .] - bad_regex = metacharacters.any? do |char| - ARGV.any? do |arg| - arg.include?(char) && !arg.start_with?("/") + + if $stdout.tty? + metacharacters = %w[\\ | ( ) [ ] { } ^ $ * + ? .] + bad_regex = metacharacters.any? do |char| + ARGV.any? do |arg| + arg.include?(char) && !arg.start_with?("/") + end + end + if ARGV.any? && bad_regex + ohai "Did you mean to perform a regular expression search?" + ohai "Surround your query with /slashes/ to search by regex." end end - if ARGV.any? && bad_regex - ohai "Did you mean to perform a regular expression search?" - ohai "Surround your query with /slashes/ to search by regex." - end + raise SEARCH_ERROR_QUEUE.pop unless SEARCH_ERROR_QUEUE.empty? end