Improve formula/cask disambiguation

This commit is contained in:
nandahkrishna 2021-03-04 01:01:56 +05:30
parent f11786d63d
commit 7d5216c500
No known key found for this signature in database
GPG Key ID: 067E5FCD58ADF3AA
3 changed files with 41 additions and 25 deletions

View File

@ -51,6 +51,15 @@ module Homebrew
if formulae_and_casks if formulae_and_casks
Livecheck.load_other_tap_strategies(formulae_and_casks) Livecheck.load_other_tap_strategies(formulae_and_casks)
ambiguous_casks = []
if !args.formula? && !args.cask?
ambiguous_casks = formulae_and_casks
.group_by { |item| Livecheck.formula_or_cask_name(item, full_name: true) }
.select { |_name, items| items.length > 1 }
.values.flatten
.select { |item| item.is_a?(Cask::Cask) }
end
formulae_and_casks.each_with_index do |formula_or_cask, i| formulae_and_casks.each_with_index do |formula_or_cask, i|
puts if i.positive? puts if i.positive?
@ -68,7 +77,13 @@ module Homebrew
end end
package_data = Repology.single_package_query(name, repository: repository) package_data = Repology.single_package_query(name, repository: repository)
retrieve_and_display_info(formula_or_cask, name, package_data&.values&.first, args: args) retrieve_and_display_info(
formula_or_cask,
name,
package_data&.values&.first,
args: args,
ambiguous_cask: ambiguous_casks.include?(formula_or_cask),
)
end end
else else
api_response = {} api_response = {}
@ -105,9 +120,14 @@ module Homebrew
next next
end end
name = Livecheck.formula_or_cask_name(formula_or_cask) name = Livecheck.formula_or_cask_name(formula_or_cask)
ambiguous_cask = begin
formula_or_cask.is_a?(Cask::Cask) && !args.cask? && Formula[name] ? true : false
rescue FormulaUnavailableError
false
end
puts if i.positive? puts if i.positive?
retrieve_and_display_info(formula_or_cask, name, repositories, args: args) retrieve_and_display_info(formula_or_cask, name, repositories, args: args, ambiguous_cask: ambiguous_cask)
break if limit && i >= limit break if limit && i >= limit
end end
@ -145,7 +165,7 @@ module Homebrew
pull_requests pull_requests
end end
def retrieve_and_display_info(formula_or_cask, name, repositories, args:) def retrieve_and_display_info(formula_or_cask, name, repositories, args:, ambiguous_cask: false)
current_version = if formula_or_cask.is_a?(Formula) current_version = if formula_or_cask.is_a?(Formula)
formula_or_cask.stable.version formula_or_cask.stable.version
else else
@ -161,12 +181,7 @@ module Homebrew
livecheck_latest = livecheck_result(formula_or_cask) livecheck_latest = livecheck_result(formula_or_cask)
pull_requests = retrieve_pull_requests(formula_or_cask, name) unless args.no_pull_requests? pull_requests = retrieve_pull_requests(formula_or_cask, name) unless args.no_pull_requests?
name += begin name += " (cask)" if ambiguous_cask
(" (cask)" if formula_or_cask.is_a?(Cask::Cask) && !args.cask? && Formula[name]).to_s
rescue FormulaUnavailableError
""
end
title = if current_version == repology_latest && title = if current_version == repology_latest &&
current_version == livecheck_latest current_version == livecheck_latest
"#{name} is up to date!" "#{name} is up to date!"

View File

@ -105,7 +105,7 @@ module Homebrew
options = { options = {
json: args.json?, json: args.json?,
full_name: args.full_name?, full_name: args.full_name?,
handle_name_conflict: !args.cask?, handle_name_conflict: !args.formula? && !args.cask?,
newer_only: args.newer_only?, newer_only: args.newer_only?,
quiet: args.quiet?, quiet: args.quiet?,
debug: args.debug?, debug: args.debug?,

View File

@ -63,7 +63,7 @@ module Homebrew
# Uses `formulae_and_casks_to_check` to identify taps in use other than # Uses `formulae_and_casks_to_check` to identify taps in use other than
# homebrew/core and homebrew/cask and loads strategies from them. # homebrew/core and homebrew/cask and loads strategies from them.
sig { params(formulae_and_casks_to_check: T::Enumerable[T.any(Formula, Cask::Cask)]).void } sig { params(formulae_and_casks_to_check: T::Array[T.any(Formula, Cask::Cask)]).void }
def load_other_tap_strategies(formulae_and_casks_to_check) def load_other_tap_strategies(formulae_and_casks_to_check)
other_taps = {} other_taps = {}
formulae_and_casks_to_check.each do |formula_or_cask| formulae_and_casks_to_check.each do |formula_or_cask|
@ -86,7 +86,7 @@ module Homebrew
# `formulae_and_casks_to_check` array and prints the results. # `formulae_and_casks_to_check` array and prints the results.
sig { sig {
params( params(
formulae_and_casks_to_check: T::Enumerable[T.any(Formula, Cask::Cask)], formulae_and_casks_to_check: T::Array[T.any(Formula, Cask::Cask)],
full_name: T::Boolean, full_name: T::Boolean,
handle_name_conflict: T::Boolean, handle_name_conflict: T::Boolean,
json: T::Boolean, json: T::Boolean,
@ -103,6 +103,15 @@ module Homebrew
) )
load_other_tap_strategies(formulae_and_casks_to_check) load_other_tap_strategies(formulae_and_casks_to_check)
ambiguous_casks = []
if handle_name_conflict
ambiguous_casks = formulae_and_casks_to_check
.group_by { |item| formula_or_cask_name(item, full_name: true) }
.select { |_name, items| items.length > 1 }
.values.flatten
.select { |item| item.is_a?(Cask::Cask) }
end
has_a_newer_upstream_version = T.let(false, T::Boolean) has_a_newer_upstream_version = T.let(false, T::Boolean)
if json && !quiet && $stderr.tty? if json && !quiet && $stderr.tty?
@ -224,7 +233,7 @@ module Homebrew
next info next info
end end
print_latest_version(info, verbose: verbose, handle_name_conflict: handle_name_conflict) print_latest_version(info, verbose: verbose, ambiguous_cask: ambiguous_casks.include?(formula_or_cask))
nil nil
rescue => e rescue => e
Homebrew.failed = true Homebrew.failed = true
@ -234,11 +243,7 @@ module Homebrew
status_hash(formula_or_cask, "error", [e.to_s], full_name: full_name, verbose: verbose) status_hash(formula_or_cask, "error", [e.to_s], full_name: full_name, verbose: verbose)
elsif !quiet elsif !quiet
name = formula_or_cask_name(formula_or_cask, full_name: full_name) name = formula_or_cask_name(formula_or_cask, full_name: full_name)
name += begin name += " (cask)" if ambiguous_casks.include?(formula_or_cask)
(" (cask)" if cask && handle_name_conflict && Formula[name]).to_s
rescue FormulaUnavailableError
""
end
onoe "#{Tty.blue}#{name}#{Tty.reset}: #{e}" onoe "#{Tty.blue}#{name}#{Tty.reset}: #{e}"
$stderr.puts e.backtrace if debug && !e.is_a?(Livecheck::Error) $stderr.puts e.backtrace if debug && !e.is_a?(Livecheck::Error)
@ -317,14 +322,10 @@ module Homebrew
end end
# Formats and prints the livecheck result for a formula. # Formats and prints the livecheck result for a formula.
sig { params(info: Hash, verbose: T::Boolean, handle_name_conflict: T::Boolean).void } sig { params(info: Hash, verbose: T::Boolean, ambiguous_cask: T::Boolean).void }
def print_latest_version(info, verbose:, handle_name_conflict: false) def print_latest_version(info, verbose:, ambiguous_cask: false)
formula_or_cask_s = "#{Tty.blue}#{info[:formula] || info[:cask]}#{Tty.reset}" formula_or_cask_s = "#{Tty.blue}#{info[:formula] || info[:cask]}#{Tty.reset}"
formula_or_cask_s += begin formula_or_cask_s += " (cask)" if ambiguous_cask
(" (cask)" if info[:cask] && handle_name_conflict && Formula[info[:cask]]).to_s
rescue FormulaUnavailableError
""
end
formula_or_cask_s += " (guessed)" if !info[:meta][:livecheckable] && verbose formula_or_cask_s += " (guessed)" if !info[:meta][:livecheckable] && verbose
current_s = if info[:version][:newer_than_upstream] current_s = if info[:version][:newer_than_upstream]