diff options
| author | Dan Martinez | 2015-05-05 15:29:01 -0700 |
|---|---|---|
| committer | Mike McQuaid | 2015-09-08 15:23:37 +0100 |
| commit | 837437416840d4c4f132b7e4ba2ea0fa2f861668 (patch) | |
| tree | a05615c66686eb93cf7cea2b5d8eed66e82be4f2 /Library/Homebrew/cmd | |
| parent | c4ceaabfc19bedc70be53f2df2be7546bb9286e8 (diff) | |
| download | brew-837437416840d4c4f132b7e4ba2ea0fa2f861668.tar.bz2 | |
Improve description searching and add a cache.
Closes Homebrew/homebrew#42281.
Signed-off-by: Mike McQuaid <mike@mikemcquaid.com>
Diffstat (limited to 'Library/Homebrew/cmd')
| -rw-r--r-- | Library/Homebrew/cmd/desc.rb | 40 | ||||
| -rw-r--r-- | Library/Homebrew/cmd/search.rb | 7 | ||||
| -rw-r--r-- | Library/Homebrew/cmd/tap.rb | 2 | ||||
| -rw-r--r-- | Library/Homebrew/cmd/untap.rb | 2 | ||||
| -rw-r--r-- | Library/Homebrew/cmd/update.rb | 2 |
5 files changed, 48 insertions, 5 deletions
diff --git a/Library/Homebrew/cmd/desc.rb b/Library/Homebrew/cmd/desc.rb new file mode 100644 index 000000000..77078e8f5 --- /dev/null +++ b/Library/Homebrew/cmd/desc.rb @@ -0,0 +1,40 @@ +require "descriptions" +require "cmd/search" + +module Homebrew + def desc + if ARGV.options_only.empty? + if ARGV.named.empty? + raise FormulaUnspecifiedError + exit + end + results = Descriptions.named(ARGV.formulae.map(&:full_name)) + else + if ARGV.options_only.count != 1 + odie "Pick one, and only one, of -s/--search, -n/--name, or -d/--description." + end + + search_arg = ARGV.options_only.first + + search_type = case search_arg + when '-s', '--search' + :either + when '-n', '--name' + :name + when '-d', '--description' + :desc + else + odie "Unrecognized option '#{search_arg}'." + end + + if arg = ARGV.named.first + regex = Homebrew::query_regexp(arg) + results = Descriptions.search(regex, search_type) + else + odie "You must provide a search term." + end + end + + results.print unless results.nil? + end +end diff --git a/Library/Homebrew/cmd/search.rb b/Library/Homebrew/cmd/search.rb index 10e0a8269..9e5f28815 100644 --- a/Library/Homebrew/cmd/search.rb +++ b/Library/Homebrew/cmd/search.rb @@ -3,6 +3,7 @@ require "blacklist" require "utils" require "thread" require "official_taps" +require 'descriptions' module Homebrew SEARCH_ERROR_QUEUE = Queue.new @@ -23,11 +24,7 @@ module Homebrew elsif ARGV.include? "--desc" query = ARGV.next rx = query_regexp(query) - Formula.each do |formula| - if formula.desc =~ rx - puts "#{Tty.white}#{formula.full_name}:#{Tty.reset} #{formula.desc}" - end - end + Descriptions.search(rx, :desc).print elsif ARGV.empty? puts_columns Formula.full_names elsif ARGV.first =~ HOMEBREW_TAP_FORMULA_REGEX diff --git a/Library/Homebrew/cmd/tap.rb b/Library/Homebrew/cmd/tap.rb index 0c8960cbd..291407aff 100644 --- a/Library/Homebrew/cmd/tap.rb +++ b/Library/Homebrew/cmd/tap.rb @@ -1,4 +1,5 @@ require "tap" +require "descriptions" module Homebrew def tap @@ -41,6 +42,7 @@ module Homebrew formula_count = tap.formula_files.size puts "Tapped #{formula_count} formula#{plural(formula_count, "e")} (#{tap.path.abv})" + Descriptions.cache_formulae(tap.formula_names) if !clone_target && tap.private? puts <<-EOS.undent diff --git a/Library/Homebrew/cmd/untap.rb b/Library/Homebrew/cmd/untap.rb index 1e8bfdcab..22dab7383 100644 --- a/Library/Homebrew/cmd/untap.rb +++ b/Library/Homebrew/cmd/untap.rb @@ -1,4 +1,5 @@ require "cmd/tap" # for tap_args +require "descriptions" module Homebrew def untap @@ -13,6 +14,7 @@ module Homebrew tap.unpin if tap.pinned? formula_count = tap.formula_files.size + Descriptions.uncache_formulae(tap.formula_names) tap.path.rmtree tap.path.dirname.rmdir_if_possible puts "Untapped #{formula_count} formula#{plural(formula_count, "e")}" diff --git a/Library/Homebrew/cmd/update.rb b/Library/Homebrew/cmd/update.rb index 1d4eb5928..4be763b6a 100644 --- a/Library/Homebrew/cmd/update.rb +++ b/Library/Homebrew/cmd/update.rb @@ -2,6 +2,7 @@ require "cmd/tap" require "formula_versions" require "migrator" require "formulary" +require "descriptions" module Homebrew def update @@ -100,6 +101,7 @@ module Homebrew puts "Updated Homebrew from #{master_updater.initial_revision[0, 8]} to #{master_updater.current_revision[0, 8]}." report.dump end + Descriptions.update_cache(report) end private |
