From 961d79011e0f0b2c63cf33f7818a4f0437e1643e Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Tue, 15 Aug 2017 10:25:51 +0100 Subject: [PATCH] search: explain why it takes the time it does. Provide a bit of clarity that this isn't just searching a local database but doing an GitHub API and Git history query. --- Library/Homebrew/cmd/search.rb | 10 ++++++++++ Library/Homebrew/test/cmd/search_spec.rb | 6 +++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/cmd/search.rb b/Library/Homebrew/cmd/search.rb index 0d47f8ab17..53767e75f9 100644 --- a/Library/Homebrew/cmd/search.rb +++ b/Library/Homebrew/cmd/search.rb @@ -58,12 +58,14 @@ module Homebrew regex = query_regexp(query) local_results = search_formulae(regex) puts Formatter.columns(local_results) unless local_results.empty? + tap_results = search_taps(query) puts Formatter.columns(tap_results) unless tap_results.empty? if $stdout.tty? count = local_results.length + tap_results.length + ohai "Searching blacklisted, migrated and deleted formulae..." if reason = Homebrew::MissingFormula.reason(query, silent: true) if count > 0 puts @@ -101,6 +103,11 @@ module Homebrew end def search_taps(query) + return [] if ENV["HOMEBREW_NO_GITHUB_API"] + + # Use stderr to avoid breaking parsed output + $stderr.puts Formatter.headline("Searching taps on GitHub...", color: :blue) + valid_dirnames = ["Formula", "HomebrewFormula", "Casks", "."].freeze matches = GitHub.search_code("user:Homebrew", "user:caskroom", "filename:#{query}", "extension:rb") [*matches].map do |match| @@ -113,6 +120,9 @@ module Homebrew end def search_formulae(regex) + # Use stderr to avoid breaking parsed output + $stderr.puts Formatter.headline("Searching local taps...", color: :blue) + aliases = Formula.alias_full_names results = (Formula.full_names + aliases).grep(regex).sort diff --git a/Library/Homebrew/test/cmd/search_spec.rb b/Library/Homebrew/test/cmd/search_spec.rb index 7c97e6e357..77c2c63521 100644 --- a/Library/Homebrew/test/cmd/search_spec.rb +++ b/Library/Homebrew/test/cmd/search_spec.rb @@ -14,7 +14,7 @@ describe "brew search", :integration_test do it "supports searching by name" do expect { brew "search", "testball" } .to output(/testball/).to_stdout - .and not_to_output.to_stderr + .and output(/Searching/).to_stderr .and be_a_success end @@ -25,10 +25,10 @@ describe "brew search", :integration_test do .and be_a_success end - it "falls back to a tap search when no formula is found" do + it "falls back to a GitHub tap search when no formula is found", :needs_network do expect { brew "search", "caskroom/cask/firefox" } .to output(/firefox/).to_stdout - .and not_to_output.to_stderr + .and output(/Searching/).to_stderr .and be_a_success end