Show casks in install not found output

- Move `search_names` and `print_missing_formula_help` out of `cmd/search.rb` to `search.rb`
- Change to using those functions in `cmd/install.rb` when a formula or cask doesn't exist
This commit is contained in:
apainintheneck 2022-12-10 12:59:06 -08:00
parent 11cdffb4fe
commit a481729ade
3 changed files with 68 additions and 88 deletions

View File

@ -278,48 +278,26 @@ module Homebrew
# formula was found, but there's a problem with its implementation). # formula was found, but there's a problem with its implementation).
$stderr.puts e.backtrace if Homebrew::EnvConfig.developer? $stderr.puts e.backtrace if Homebrew::EnvConfig.developer?
ofail e.message ofail e.message
rescue FormulaOrCaskUnavailableError => e rescue FormulaOrCaskUnavailableError, Cask::CaskUnavailableError => e
if e.name == "updog" # formula name or cask token
name = e.try(:name) || e.token
if name == "updog"
ofail "What's updog?" ofail "What's updog?"
return return
end end
opoo e opoo e
ohai "Searching for similarly named formulae..." ohai "Searching for similarly named formulae and casks..."
formulae_search_results = search_formulae(e.name)
case formulae_search_results.length
when 0
ofail "No similarly named formulae found."
when 1
puts "This similarly named formula was found:"
puts formulae_search_results
puts "To install it, run:\n brew install #{formulae_search_results.first}"
else
puts "These similarly named formulae were found:"
puts Formatter.columns(formulae_search_results)
puts "To install one of them, run (for example):\n brew install #{formulae_search_results.first}"
end
if (reason = MissingFormula.reason(e.name)) # Don't treat formula/cask name as a regex
$stderr.puts reason query = string_or_regex = name
return if search_names(query, string_or_regex, args)
end puts <<~EOL
# Do not search taps if the formula name is qualified To install one of them, run:
return if e.name.include?("/") brew install 'package_name'
EOL
taps_search_results = search_taps(e.name)[:formulae]
case taps_search_results.length
when 0
ofail "No formulae found in taps."
when 1
puts "This formula was found in a tap:"
puts taps_search_results
puts "To install it, run:\n brew install #{taps_search_results.first}"
else
puts "These formulae were found in taps:"
puts Formatter.columns(taps_search_results)
puts "To install one of them, run (for example):\n brew install #{taps_search_results.first}"
end end
end end
end end

View File

@ -128,57 +128,4 @@ module Homebrew
GitHub.print_pull_requests_matching(query, only) GitHub.print_pull_requests_matching(query, only)
end end
def search_names(query, string_or_regex, args)
remote_results = search_taps(query, silent: true)
local_formulae = search_formulae(string_or_regex)
remote_formulae = remote_results[:formulae]
all_formulae = local_formulae + remote_formulae
local_casks = search_casks(string_or_regex)
remote_casks = remote_results[:casks]
all_casks = local_casks + remote_casks
print_formulae = args.formula?
print_casks = args.cask?
print_formulae = print_casks = true if !print_formulae && !print_casks
print_formulae &&= all_formulae.any?
print_casks &&= all_casks.any?
if print_formulae
if $stdout.tty?
ohai "Formulae", Formatter.columns(all_formulae)
else
puts all_formulae
end
end
puts if print_formulae && print_casks
if print_casks
if $stdout.tty?
ohai "Casks", Formatter.columns(all_casks)
else
puts all_casks
end
end
count = all_formulae.count + all_casks.count
print_missing_formula_help(query, count.positive?) if local_casks.exclude?(query)
odie "No formulae or casks found for #{query.inspect}." if count.zero?
end
def print_missing_formula_help(query, found_matches)
return unless $stdout.tty?
reason = MissingFormula.reason(query, silent: true)
return if reason.nil?
if found_matches
puts
puts "If you meant #{query.inspect} specifically:"
end
puts reason
end
end end

View File

@ -114,6 +114,61 @@ module Homebrew
def search_casks(_string_or_regex) def search_casks(_string_or_regex)
[] []
end end
def search_names(query, string_or_regex, args)
remote_results = search_taps(query, silent: true)
local_formulae = search_formulae(string_or_regex)
remote_formulae = remote_results[:formulae]
all_formulae = local_formulae + remote_formulae
local_casks = search_casks(string_or_regex)
remote_casks = remote_results[:casks]
all_casks = local_casks + remote_casks
print_formulae = args.formula?
print_casks = args.cask?
print_formulae = print_casks = true if !print_formulae && !print_casks
print_formulae &&= all_formulae.any?
print_casks &&= all_casks.any?
count = 0
if print_formulae
if $stdout.tty?
ohai "Formulae", Formatter.columns(all_formulae)
else
puts all_formulae
end
count += all_formulae.count
end
puts if print_formulae && print_casks
if print_casks
if $stdout.tty?
ohai "Casks", Formatter.columns(all_casks)
else
puts all_casks
end
count += all_casks.count
end
print_missing_formula_help(query, count.positive?) if local_casks.exclude?(query)
odie "No formulae or casks found for #{query.inspect}." if count.zero?
!count.zero?
end
def print_missing_formula_help(query, found_matches)
return unless $stdout.tty?
reason = MissingFormula.reason(query, silent: true)
return if reason.nil?
if found_matches
puts
puts "If you meant #{query.inspect} specifically:"
end
puts reason
end
end end
end end