Skip to content
Snippets Groups Projects
Commit b5ec74c3 authored by Xu Cheng's avatar Xu Cheng
Browse files

search: various improvement


* Move listing all formula names in the top to speed up shell script.
* Simplify logic.
* Only search PR and check bad regex for tty?, which will benefit to
  shell script.

Closes Homebrew/homebrew#44985.

Signed-off-by: default avatarXu Cheng <xucheng@me.com>
parent 135efb39
No related branches found
No related tags found
No related merge requests found
......@@ -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)
tap_results = search_taps(rx)
puts_columns(tap_results)
if !query.empty? && $stdout.tty? && msg = blacklisted?(query)
unless local_results.empty?
puts
puts "If you meant #{query.inspect} precisely:"
puts
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
puts msg
end
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?
metacharacters = %w[\\ | ( ) [ ] { } ^ $ * + ? .]
bad_regex = metacharacters.any? do |char|
ARGV.any? do |arg|
arg.include?(char) && !arg.start_with?("/")
end
end
end
metacharacters = %w[\\ | ( ) [ ] { } ^ $ * + ? .]
bad_regex = metacharacters.any? do |char|
ARGV.any? do |arg|
arg.include?(char) && !arg.start_with?("/")
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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment