mirror of
https://github.com/Homebrew/brew.git
synced 2025-07-14 16:09:03 +08:00
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: Xu Cheng <xucheng@me.com>
This commit is contained in:
parent
135efb39b8
commit
b5ec74c3f6
@ -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,21 +44,20 @@ 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?
|
||||
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
|
||||
end
|
||||
|
||||
tap_results = search_taps(rx)
|
||||
puts_columns(tap_results)
|
||||
count = local_results.length + tap_results.length
|
||||
|
||||
if count == 0 && !blacklisted?(query)
|
||||
elsif count == 0
|
||||
puts "No formula found for #{query.inspect}."
|
||||
begin
|
||||
GitHub.print_pull_requests_matching(query)
|
||||
@ -67,6 +66,9 @@ module Homebrew
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if $stdout.tty?
|
||||
metacharacters = %w[\\ | ( ) [ ] { } ^ $ * + ? .]
|
||||
bad_regex = metacharacters.any? do |char|
|
||||
ARGV.any? do |arg|
|
||||
@ -77,6 +79,8 @@ module Homebrew
|
||||
ohai "Did you mean to perform a regular expression search?"
|
||||
ohai "Surround your query with /slashes/ to search by regex."
|
||||
end
|
||||
end
|
||||
|
||||
raise SEARCH_ERROR_QUEUE.pop unless SEARCH_ERROR_QUEUE.empty?
|
||||
end
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user