Merge pull request #17102 from Homebrew/only-brew-desc-search-needs-eval-all

Only `brew desc --search` needs `--eval-all`
This commit is contained in:
Mike McQuaid 2024-04-18 10:30:41 +01:00 committed by GitHub
commit 3c72da93b9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 36 additions and 20 deletions

View File

@ -38,10 +38,6 @@ module Homebrew
sig { override.void } sig { override.void }
def run def run
if !args.eval_all? && !Homebrew::EnvConfig.eval_all?
raise UsageError, "`brew desc` needs `--eval-all` passed or `HOMEBREW_EVAL_ALL` set!"
end
search_type = if args.search? search_type = if args.search?
:either :either
elsif args.name? elsif args.name?
@ -50,25 +46,29 @@ module Homebrew
:desc :desc
end end
if search_type.blank? if search_type.present?
desc = {} if !args.eval_all? && !Homebrew::EnvConfig.eval_all?
args.named.to_formulae_and_casks.each do |formula_or_cask| raise UsageError, "`brew desc --search` needs `--eval-all` passed or `HOMEBREW_EVAL_ALL` set!"
case formula_or_cask
when Formula
desc[formula_or_cask.full_name] = formula_or_cask.desc
when Cask::Cask
description = formula_or_cask.desc.presence || Formatter.warning("[no description]")
desc[formula_or_cask.full_name] = "(#{formula_or_cask.name.join(", ")}) #{description}"
else
raise TypeError, "Unsupported formula_or_cask type: #{formula_or_cask.class}"
end
end end
Descriptions.new(desc).print
else
query = args.named.join(" ") query = args.named.join(" ")
string_or_regex = Search.query_regexp(query) string_or_regex = Search.query_regexp(query)
Search.search_descriptions(string_or_regex, args, search_type:) return Search.search_descriptions(string_or_regex, args, search_type:)
end end
desc = {}
args.named.to_formulae_and_casks.each do |formula_or_cask|
case formula_or_cask
when Formula
desc[formula_or_cask.full_name] = formula_or_cask.desc
when Cask::Cask
description = formula_or_cask.desc.presence || Formatter.warning("[no description]")
desc[formula_or_cask.full_name] = "(#{formula_or_cask.name.join(", ")}) #{description}"
else
raise TypeError, "Unsupported formula_or_cask type: #{formula_or_cask.class}"
end
end
Descriptions.new(desc).print
end end
end end
end end

View File

@ -9,9 +9,25 @@ RSpec.describe Homebrew::Cmd::Desc do
it "shows a given Formula's description", :integration_test do it "shows a given Formula's description", :integration_test do
setup_test_formula "testball" setup_test_formula "testball"
expect { brew "desc", "--eval-all", "testball" } expect { brew "desc", "testball" }
.to output("testball: Some test\n").to_stdout .to output("testball: Some test\n").to_stdout
.and not_to_output.to_stderr .and not_to_output.to_stderr
.and be_a_success .and be_a_success
end end
it "errors when searching without --eval-all", :integration_test do
setup_test_formula "testball"
expect { brew "desc", "--search", "testball" }
.to output(/`brew desc --search` needs `--eval-all` passed or `HOMEBREW_EVAL_ALL` set!/).to_stderr
.and be_a_failure
end
it "successfully searches with --search --eval-all", :integration_test do
setup_test_formula "testball"
expect { brew "desc", "--search", "--eval-all", "ball" }
.to output(/testball: Some test/).to_stdout
.and not_to_output.to_stderr
end
end end