Apply suggestions from code review
Co-authored-by: Mike McQuaid <mike@mikemcquaid.com>
This commit is contained in:
parent
ab0e427d3e
commit
8ddf9b37bd
@ -40,16 +40,16 @@ module Homebrew
|
|||||||
raise UsageError, "`--limit` must be used with either `--formula` or `--cask`."
|
raise UsageError, "`--limit` must be used with either `--formula` or `--cask`."
|
||||||
end
|
end
|
||||||
|
|
||||||
formulae_and_casks =
|
formulae_and_casks = if args.formula?
|
||||||
if args.formula?
|
args.named.to_formulae
|
||||||
args.named.to_formulae
|
elsif args.cask?
|
||||||
elsif args.cask?
|
args.named.to_casks
|
||||||
args.named.to_casks
|
else
|
||||||
else
|
args.named.to_formulae_and_casks
|
||||||
args.named.to_formulae_and_casks
|
end
|
||||||
end&.sort_by do |formula_or_cask|
|
formulae_and_casks = formulae_and_casks&.sort_by do |formula_or_cask|
|
||||||
formula_or_cask.respond_to?(:token) ? formula_or_cask.token : formula_or_cask.name
|
formula_or_cask.respond_to?(:token) ? formula_or_cask.token : formula_or_cask.name
|
||||||
end
|
end
|
||||||
|
|
||||||
limit = args.limit.to_i if args.limit.present?
|
limit = args.limit.to_i if args.limit.present?
|
||||||
|
|
||||||
@ -58,19 +58,20 @@ module Homebrew
|
|||||||
|
|
||||||
ambiguous_casks = []
|
ambiguous_casks = []
|
||||||
if !args.formula? && !args.cask?
|
if !args.formula? && !args.cask?
|
||||||
ambiguous_casks = formulae_and_casks
|
ambiguous_casks = formulae_and_casks.group_by { |item| Livecheck.formula_or_cask_name(item, full_name: true) }
|
||||||
.group_by { |item| Livecheck.formula_or_cask_name(item, full_name: true) }
|
.values
|
||||||
.select { |_name, items| items.length > 1 }
|
.select { |items| items.length > 1 }
|
||||||
.values.flatten
|
.flatten
|
||||||
.select { |item| item.is_a?(Cask::Cask) }
|
.select { |item| item.is_a?(Cask::Cask) }
|
||||||
end
|
end
|
||||||
|
|
||||||
ambiguous_names = []
|
ambiguous_names = []
|
||||||
unless args.full_name?
|
unless args.full_name?
|
||||||
ambiguous_names = (formulae_and_casks - ambiguous_casks)
|
ambiguous_names =
|
||||||
.group_by { |item| Livecheck.formula_or_cask_name(item) }
|
(formulae_and_casks - ambiguous_casks).group_by { |item| Livecheck.formula_or_cask_name(item) }
|
||||||
.select { |_name, items| items.length > 1 }
|
.values
|
||||||
.values.flatten
|
.select { |items| items.length > 1 }
|
||||||
|
.flatten
|
||||||
end
|
end
|
||||||
|
|
||||||
formulae_and_casks.each_with_index do |formula_or_cask, i|
|
formulae_and_casks.each_with_index do |formula_or_cask, i|
|
||||||
@ -135,7 +136,7 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
name = Livecheck.formula_or_cask_name(formula_or_cask)
|
name = Livecheck.formula_or_cask_name(formula_or_cask)
|
||||||
ambiguous_cask = begin
|
ambiguous_cask = begin
|
||||||
formula_or_cask.is_a?(Cask::Cask) && !args.cask? && Formula[name] ? true : false
|
formula_or_cask.is_a?(Cask::Cask) && !args.cask? && Formula[name]
|
||||||
rescue FormulaUnavailableError
|
rescue FormulaUnavailableError
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
|
|||||||
@ -61,44 +61,44 @@ module Homebrew
|
|||||||
puts ENV["HOMEBREW_LIVECHECK_WATCHLIST"] if ENV["HOMEBREW_LIVECHECK_WATCHLIST"].present?
|
puts ENV["HOMEBREW_LIVECHECK_WATCHLIST"] if ENV["HOMEBREW_LIVECHECK_WATCHLIST"].present?
|
||||||
end
|
end
|
||||||
|
|
||||||
formulae_and_casks_to_check =
|
formulae_and_casks_to_check = if args.tap
|
||||||
if args.tap
|
tap = Tap.fetch(args.tap)
|
||||||
tap = Tap.fetch(args.tap)
|
formulae = args.cask? ? [] : tap.formula_files.map { |path| Formulary.factory(path) }
|
||||||
formulae = args.cask? ? [] : tap.formula_files.map { |path| Formulary.factory(path) }
|
casks = args.formula? ? [] : tap.cask_files.map { |path| Cask::CaskLoader.load(path) }
|
||||||
casks = args.formula? ? [] : tap.cask_files.map { |path| Cask::CaskLoader.load(path) }
|
formulae + casks
|
||||||
formulae + casks
|
elsif args.installed?
|
||||||
elsif args.installed?
|
formulae = args.cask? ? [] : Formula.installed
|
||||||
formulae = args.cask? ? [] : Formula.installed
|
casks = args.formula? ? [] : Cask::Caskroom.casks
|
||||||
casks = args.formula? ? [] : Cask::Caskroom.casks
|
formulae + casks
|
||||||
formulae + casks
|
elsif args.all?
|
||||||
elsif args.all?
|
formulae = args.cask? ? [] : Formula.to_a
|
||||||
formulae = args.cask? ? [] : Formula.to_a
|
casks = args.formula? ? [] : Cask::Cask.to_a
|
||||||
casks = args.formula? ? [] : Cask::Cask.to_a
|
formulae + casks
|
||||||
formulae + casks
|
elsif args.named.present?
|
||||||
elsif args.named.present?
|
if args.formula?
|
||||||
if args.formula?
|
args.named.to_formulae
|
||||||
args.named.to_formulae
|
elsif args.cask?
|
||||||
elsif args.cask?
|
args.named.to_casks
|
||||||
args.named.to_casks
|
|
||||||
else
|
|
||||||
args.named.to_formulae_and_casks
|
|
||||||
end
|
|
||||||
elsif File.exist?(WATCHLIST_PATH)
|
|
||||||
begin
|
|
||||||
names = Pathname.new(WATCHLIST_PATH).read.lines
|
|
||||||
.reject { |line| line.start_with?("#") || line.blank? }
|
|
||||||
.map(&:strip)
|
|
||||||
|
|
||||||
named_args = T.unsafe(CLI::NamedArgs).new(*names, parent: args)
|
|
||||||
named_args.to_formulae_and_casks(ignore_unavailable: true)
|
|
||||||
rescue Errno::ENOENT => e
|
|
||||||
onoe e
|
|
||||||
end
|
|
||||||
else
|
else
|
||||||
raise UsageError, "A watchlist file is required when no arguments are given."
|
args.named.to_formulae_and_casks
|
||||||
end&.sort_by do |formula_or_cask|
|
|
||||||
formula_or_cask.respond_to?(:token) ? formula_or_cask.token : formula_or_cask.name
|
|
||||||
end
|
end
|
||||||
|
elsif File.exist?(WATCHLIST_PATH)
|
||||||
|
begin
|
||||||
|
names = Pathname.new(WATCHLIST_PATH).read.lines
|
||||||
|
.reject { |line| line.start_with?("#") || line.blank? }
|
||||||
|
.map(&:strip)
|
||||||
|
|
||||||
|
named_args = T.unsafe(CLI::NamedArgs).new(*names, parent: args)
|
||||||
|
named_args.to_formulae_and_casks(ignore_unavailable: true)
|
||||||
|
rescue Errno::ENOENT => e
|
||||||
|
onoe e
|
||||||
|
end
|
||||||
|
else
|
||||||
|
raise UsageError, "A watchlist file is required when no arguments are given."
|
||||||
|
end
|
||||||
|
formulae_and_casks_to_check = formulae_and_casks_to_check.sort_by do |formula_or_cask|
|
||||||
|
formula_or_cask.respond_to?(:token) ? formula_or_cask.token : formula_or_cask.name
|
||||||
|
end
|
||||||
|
|
||||||
raise UsageError, "No formulae or casks to check." if formulae_and_casks_to_check.blank?
|
raise UsageError, "No formulae or casks to check." if formulae_and_casks_to_check.blank?
|
||||||
|
|
||||||
|
|||||||
@ -105,19 +105,20 @@ module Homebrew
|
|||||||
|
|
||||||
ambiguous_casks = []
|
ambiguous_casks = []
|
||||||
if handle_name_conflict
|
if handle_name_conflict
|
||||||
ambiguous_casks = formulae_and_casks_to_check
|
ambiguous_casks = formulae_and_casks_to_check.group_by { |item| formula_or_cask_name(item, full_name: true) }
|
||||||
.group_by { |item| formula_or_cask_name(item, full_name: true) }
|
.values
|
||||||
.select { |_name, items| items.length > 1 }
|
.select { |items| items.length > 1 }
|
||||||
.values.flatten
|
.flatten
|
||||||
.select { |item| item.is_a?(Cask::Cask) }
|
.select { |item| item.is_a?(Cask::Cask) }
|
||||||
end
|
end
|
||||||
|
|
||||||
ambiguous_names = []
|
ambiguous_names = []
|
||||||
unless full_name
|
unless full_name
|
||||||
ambiguous_names = (formulae_and_casks_to_check - ambiguous_casks)
|
ambiguous_names =
|
||||||
.group_by { |item| formula_or_cask_name(item) }
|
(formulae_and_casks_to_check - ambiguous_casks).group_by { |item| formula_or_cask_name(item) }
|
||||||
.select { |_name, items| items.length > 1 }
|
.values
|
||||||
.values.flatten
|
.select { |items| items.length > 1 }
|
||||||
|
.flatten
|
||||||
end
|
end
|
||||||
|
|
||||||
has_a_newer_upstream_version = T.let(false, T::Boolean)
|
has_a_newer_upstream_version = T.let(false, T::Boolean)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user