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:
parent
11cdffb4fe
commit
a481729ade
@ -278,48 +278,26 @@ module Homebrew
|
||||
# formula was found, but there's a problem with its implementation).
|
||||
$stderr.puts e.backtrace if Homebrew::EnvConfig.developer?
|
||||
ofail e.message
|
||||
rescue FormulaOrCaskUnavailableError => e
|
||||
if e.name == "updog"
|
||||
rescue FormulaOrCaskUnavailableError, Cask::CaskUnavailableError => e
|
||||
# formula name or cask token
|
||||
name = e.try(:name) || e.token
|
||||
|
||||
if name == "updog"
|
||||
ofail "What's updog?"
|
||||
return
|
||||
end
|
||||
|
||||
opoo e
|
||||
ohai "Searching for similarly named formulae..."
|
||||
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
|
||||
ohai "Searching for similarly named formulae and casks..."
|
||||
|
||||
if (reason = MissingFormula.reason(e.name))
|
||||
$stderr.puts reason
|
||||
return
|
||||
end
|
||||
# Don't treat formula/cask name as a regex
|
||||
query = string_or_regex = name
|
||||
if search_names(query, string_or_regex, args)
|
||||
puts <<~EOL
|
||||
|
||||
# Do not search taps if the formula name is qualified
|
||||
return if e.name.include?("/")
|
||||
|
||||
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}"
|
||||
To install one of them, run:
|
||||
brew install 'package_name'
|
||||
EOL
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -128,57 +128,4 @@ module Homebrew
|
||||
|
||||
GitHub.print_pull_requests_matching(query, only)
|
||||
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
|
||||
|
||||
@ -114,6 +114,61 @@ module Homebrew
|
||||
def search_casks(_string_or_regex)
|
||||
[]
|
||||
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
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user