From 69c16739d222cce9f46a760646d6d57b6b2f3c11 Mon Sep 17 00:00:00 2001 From: Carlo Cabrera <30379873+carlocab@users.noreply.github.com> Date: Tue, 9 May 2023 18:07:32 +0800 Subject: [PATCH] fetch: remove use of `args` from CLI parser See discussion at #15382. --- Library/Homebrew/cmd/--cache.rb | 3 ++- Library/Homebrew/cmd/fetch.rb | 3 ++- Library/Homebrew/fetch.rb | 17 ++++++++++++----- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/Library/Homebrew/cmd/--cache.rb b/Library/Homebrew/cmd/--cache.rb index 26cb74200d..c359612c65 100644 --- a/Library/Homebrew/cmd/--cache.rb +++ b/Library/Homebrew/cmd/--cache.rb @@ -58,7 +58,8 @@ module Homebrew sig { params(formula: Formula, args: CLI::Args).void } 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 elsif args.HEAD? puts formula.head.cached_download diff --git a/Library/Homebrew/cmd/fetch.rb b/Library/Homebrew/cmd/fetch.rb index 744e317b29..700a9dce6f 100644 --- a/Library/Homebrew/cmd/fetch.rb +++ b/Library/Homebrew/cmd/fetch.rb @@ -96,7 +96,8 @@ module Homebrew f.print_tap_action verb: "Fetching" 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 f.clear_cache if args.force? f.fetch_bottle_tab diff --git a/Library/Homebrew/fetch.rb b/Library/Homebrew/fetch.rb index ea5095eab5..f7ece30356 100644 --- a/Library/Homebrew/fetch.rb +++ b/Library/Homebrew/fetch.rb @@ -4,16 +4,23 @@ module Homebrew # @api private module Fetch - sig { params(formula: Formula, args: CLI::Args).returns(T::Boolean) } - def fetch_bottle?(formula, args:) + sig { + 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 - return true if args.force_bottle? && bottle.present? - return true if args.bottle_tag.present? && formula.bottled?(args.bottle_tag&.to_sym) + return true if force_bottle && bottle.present? + return true if bottle_tag.present? && formula.bottled?(bottle_tag) bottle.present? && formula.pour_bottle? && - args.build_from_source_formulae.exclude?(formula.full_name) && + build_from_source_formulae.exclude?(formula.full_name) && bottle.compatible_locations? end end