Use API for description searches
Both `brew search --desc` and `brew desc --search` use API for cask and formula searches unless `--eval-all` or `HOMEBREW_EVAL_ALL` set. Description searches do not use the description cache or eval any formulas/casks. - With `--eval-all`, description search reverts to the old behavior. - Warn if description search exludes any formulae/casks (because `--eval-all` not set). - Enforce `--eval-all` requirement if NO_INSTALL_FROM_API set.
This commit is contained in:
parent
2bc5e994c4
commit
99486c8107
@ -47,7 +47,7 @@ module Homebrew
|
||||
end
|
||||
|
||||
if search_type.present?
|
||||
if !args.eval_all? && !Homebrew::EnvConfig.eval_all?
|
||||
if !args.eval_all? && !Homebrew::EnvConfig.eval_all? && Homebrew::EnvConfig.no_install_from_api?
|
||||
raise UsageError, "`brew desc --search` needs `--eval-all` passed or `HOMEBREW_EVAL_ALL` set!"
|
||||
end
|
||||
|
||||
|
||||
@ -70,7 +70,7 @@ module Homebrew
|
||||
string_or_regex = Search.query_regexp(query)
|
||||
|
||||
if args.desc?
|
||||
if !args.eval_all? && !Homebrew::EnvConfig.eval_all?
|
||||
if !args.eval_all? && !Homebrew::EnvConfig.eval_all? && Homebrew::EnvConfig.no_install_from_api?
|
||||
raise UsageError, "`brew search --desc` needs `--eval-all` passed or `HOMEBREW_EVAL_ALL` set!"
|
||||
end
|
||||
|
||||
|
||||
@ -8,8 +8,10 @@ require "search"
|
||||
# Helper class for printing and searching descriptions.
|
||||
class Descriptions
|
||||
# Given a regex, find all formulae whose specified fields contain a match.
|
||||
def self.search(string_or_regex, field, cache_store, eval_all = Homebrew::EnvConfig.eval_all?)
|
||||
cache_store.populate_if_empty!(eval_all:)
|
||||
def self.search(string_or_regex, field, cache_store,
|
||||
eval_all = Homebrew::EnvConfig.eval_all?, cache_store_hash: false)
|
||||
|
||||
cache_store.populate_if_empty!(eval_all:) unless cache_store_hash
|
||||
|
||||
results = case field
|
||||
when :name
|
||||
|
||||
@ -22,9 +22,19 @@ module Homebrew
|
||||
|
||||
if args.formula? || both
|
||||
ohai "Formulae"
|
||||
CacheStoreDatabase.use(:descriptions) do |db|
|
||||
cache_store = DescriptionCacheStore.new(db)
|
||||
Descriptions.search(string_or_regex, search_type, cache_store, eval_all).print
|
||||
if eval_all
|
||||
CacheStoreDatabase.use(:descriptions) do |db|
|
||||
cache_store = DescriptionCacheStore.new(db)
|
||||
Descriptions.search(string_or_regex, search_type, cache_store, eval_all).print
|
||||
end
|
||||
else
|
||||
unofficial = Tap.all.sum { |tap| tap.official? ? 0 : tap.formula_files.size }
|
||||
if unofficial.positive?
|
||||
opoo "Use `--eval-all` to search #{unofficial} additional " \
|
||||
"#{Utils.pluralize("formula", unofficial, plural: "e")} in third party taps."
|
||||
end
|
||||
descriptions = Homebrew::API::Formula.all_formulae.transform_values { |data| data["desc"] }
|
||||
Descriptions.search(string_or_regex, search_type, descriptions, eval_all, cache_store_hash: true).print
|
||||
end
|
||||
end
|
||||
return if !args.cask? && !both
|
||||
@ -32,9 +42,19 @@ module Homebrew
|
||||
puts if both
|
||||
|
||||
ohai "Casks"
|
||||
CacheStoreDatabase.use(:cask_descriptions) do |db|
|
||||
cache_store = CaskDescriptionCacheStore.new(db)
|
||||
Descriptions.search(string_or_regex, search_type, cache_store, eval_all).print
|
||||
if eval_all
|
||||
CacheStoreDatabase.use(:cask_descriptions) do |db|
|
||||
cache_store = CaskDescriptionCacheStore.new(db)
|
||||
Descriptions.search(string_or_regex, search_type, cache_store, eval_all).print
|
||||
end
|
||||
else
|
||||
unofficial = Tap.all.sum { |tap| tap.official? ? 0 : tap.cask_files.size }
|
||||
if unofficial.positive?
|
||||
opoo "Use `--eval-all` to search #{unofficial} additional " \
|
||||
"#{Utils.pluralize("cask", unofficial)} in third party taps."
|
||||
end
|
||||
descriptions = Homebrew::API::Cask.all_casks.transform_values { |c| [c["name"].join(", "), c["desc"]] }
|
||||
Descriptions.search(string_or_regex, search_type, descriptions, eval_all, cache_store_hash: true).print
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user