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
|
SEARCH_ERROR_QUEUE = Queue.new
|
||||||
|
|
||||||
def search
|
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}"
|
exec_browser "https://www.macports.org/ports.php?by=name&substr=#{ARGV.next}"
|
||||||
elsif ARGV.include? "--fink"
|
elsif ARGV.include? "--fink"
|
||||||
exec_browser "http://pdb.finkproject.org/pdb/browse.php?summary=#{ARGV.next}"
|
exec_browser "http://pdb.finkproject.org/pdb/browse.php?summary=#{ARGV.next}"
|
||||||
@ -25,8 +27,6 @@ module Homebrew
|
|||||||
query = ARGV.next
|
query = ARGV.next
|
||||||
rx = query_regexp(query)
|
rx = query_regexp(query)
|
||||||
Descriptions.search(rx, :desc).print
|
Descriptions.search(rx, :desc).print
|
||||||
elsif ARGV.empty?
|
|
||||||
puts_columns Formula.full_names
|
|
||||||
elsif ARGV.first =~ HOMEBREW_TAP_FORMULA_REGEX
|
elsif ARGV.first =~ HOMEBREW_TAP_FORMULA_REGEX
|
||||||
query = ARGV.first
|
query = ARGV.first
|
||||||
user, repo, name = query.split("/", 3)
|
user, repo, name = query.split("/", 3)
|
||||||
@ -44,39 +44,43 @@ module Homebrew
|
|||||||
local_results = search_formulae(rx)
|
local_results = search_formulae(rx)
|
||||||
local_results_installed = local_results.select { |f| f.end_with? "(installed)" }
|
local_results_installed = local_results.select { |f| f.end_with? "(installed)" }
|
||||||
puts_columns(local_results, local_results_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)
|
tap_results = search_taps(rx)
|
||||||
puts_columns(tap_results)
|
puts_columns(tap_results)
|
||||||
count = local_results.length + tap_results.length
|
|
||||||
|
|
||||||
if count == 0 && !blacklisted?(query)
|
if $stdout.tty?
|
||||||
puts "No formula found for #{query.inspect}."
|
count = local_results.length + tap_results.length
|
||||||
begin
|
|
||||||
GitHub.print_pull_requests_matching(query)
|
if msg = blacklisted?(query)
|
||||||
rescue GitHub::Error => e
|
if count > 0
|
||||||
SEARCH_ERROR_QUEUE << e
|
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
|
end
|
||||||
end
|
end
|
||||||
metacharacters = %w[\\ | ( ) [ ] { } ^ $ * + ? .]
|
|
||||||
bad_regex = metacharacters.any? do |char|
|
if $stdout.tty?
|
||||||
ARGV.any? do |arg|
|
metacharacters = %w[\\ | ( ) [ ] { } ^ $ * + ? .]
|
||||||
arg.include?(char) && !arg.start_with?("/")
|
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
|
||||||
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?
|
raise SEARCH_ERROR_QUEUE.pop unless SEARCH_ERROR_QUEUE.empty?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user