diff options
| author | Xu Cheng | 2015-10-15 17:10:25 +0800 |
|---|---|---|
| committer | Xu Cheng | 2015-10-15 17:24:41 +0800 |
| commit | b5ec74c3f6b32cdd25b8051c1b47b3594aa1fb90 (patch) | |
| tree | fbf84e92fe10ec891fe724adcf9a1b4222a0f128 /Library/Homebrew | |
| parent | 135efb39b8f6a35071ab3b701a789b668bfc2596 (diff) | |
| download | brew-b5ec74c3f6b32cdd25b8051c1b47b3594aa1fb90.tar.bz2 | |
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>
Diffstat (limited to 'Library/Homebrew')
| -rw-r--r-- | Library/Homebrew/cmd/search.rb | 60 |
1 files changed, 32 insertions, 28 deletions
diff --git a/Library/Homebrew/cmd/search.rb b/Library/Homebrew/cmd/search.rb index 2c2f95567..3bf25a4b6 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) + 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 |
