fetch: remove use of args from CLI parser

See discussion at #15382.
This commit is contained in:
Carlo Cabrera 2023-05-09 18:07:32 +08:00
parent b3f7c6f7a5
commit 69c16739d2
No known key found for this signature in database
GPG Key ID: C74D447FC549A1D0
3 changed files with 16 additions and 7 deletions

View File

@ -58,7 +58,8 @@ module Homebrew
sig { params(formula: Formula, args: CLI::Args).void } sig { params(formula: Formula, args: CLI::Args).void }
def self.print_formula_cache(formula, args:) def self.print_formula_cache(formula, args:)
if fetch_bottle?(formula, args: args) if fetch_bottle?(formula, force_bottle: args.force_bottle?, bottle_tag: args.bottle_tag&.to_sym,
build_from_source_formulae: args.build_from_source_formulae)
puts formula.bottle_for_tag(args.bottle_tag&.to_sym)&.cached_download puts formula.bottle_for_tag(args.bottle_tag&.to_sym)&.cached_download
elsif args.HEAD? elsif args.HEAD?
puts formula.head.cached_download puts formula.head.cached_download

View File

@ -96,7 +96,8 @@ module Homebrew
f.print_tap_action verb: "Fetching" f.print_tap_action verb: "Fetching"
fetched_bottle = false fetched_bottle = false
if fetch_bottle?(f, args: args) if fetch_bottle?(f, force_bottle: args.force_bottle?, bottle_tag: args.bottle_tag&.to_sym,
build_from_source_formulae: args.build_from_source_formulae)
begin begin
f.clear_cache if args.force? f.clear_cache if args.force?
f.fetch_bottle_tab f.fetch_bottle_tab

View File

@ -4,16 +4,23 @@
module Homebrew module Homebrew
# @api private # @api private
module Fetch module Fetch
sig { params(formula: Formula, args: CLI::Args).returns(T::Boolean) } sig {
def fetch_bottle?(formula, args:) params(
formula: Formula,
force_bottle: T::Boolean,
bottle_tag: T.nilable(Symbol),
build_from_source_formulae: T::Array[String],
).returns(T::Boolean)
}
def fetch_bottle?(formula, force_bottle:, bottle_tag:, build_from_source_formulae:)
bottle = formula.bottle bottle = formula.bottle
return true if args.force_bottle? && bottle.present? return true if force_bottle && bottle.present?
return true if args.bottle_tag.present? && formula.bottled?(args.bottle_tag&.to_sym) return true if bottle_tag.present? && formula.bottled?(bottle_tag)
bottle.present? && bottle.present? &&
formula.pour_bottle? && formula.pour_bottle? &&
args.build_from_source_formulae.exclude?(formula.full_name) && build_from_source_formulae.exclude?(formula.full_name) &&
bottle.compatible_locations? bottle.compatible_locations?
end end
end end