From 0b53e54bfaea8f993dcfffd5d26db65d8231b73b Mon Sep 17 00:00:00 2001 From: thibhero Date: Wed, 5 Mar 2025 17:38:18 -0500 Subject: [PATCH] Moving ask input to Install.ask --- Library/Homebrew/cmd/install.rb | 13 +--- Library/Homebrew/cmd/reinstall.rb | 12 +--- Library/Homebrew/cmd/upgrade.rb | 14 +--- Library/Homebrew/install.rb | 106 ++++++++++++++++++------------ 4 files changed, 69 insertions(+), 76 deletions(-) diff --git a/Library/Homebrew/cmd/install.rb b/Library/Homebrew/cmd/install.rb index d14a50def1..b93b0f6397 100644 --- a/Library/Homebrew/cmd/install.rb +++ b/Library/Homebrew/cmd/install.rb @@ -307,19 +307,8 @@ module Homebrew Install.perform_preinstall_checks_once Install.check_cc_argv(args.cc) - # Main block: if asking the user is enabled, show dependency and size information. if args.ask? - ohai "Looking for bottles..." - - sized_formulae = Install.compute_sized_formulae(formulae, args: args) - sizes = Install.compute_total_sizes(sized_formulae, debug: args.debug?) - - puts "Formulae: #{sized_formulae.join(", ")}\n\n" - puts "Download Size: #{disk_usage_readable(sizes[:download])}" - puts "Install Size: #{disk_usage_readable(sizes[:installed])}" - puts "Net Install Size: #{disk_usage_readable(sizes[:net])}" if sizes[:net] != 0 - - Install.ask_input + Install.ask(formulae, args: args) end Install.install_formulae( diff --git a/Library/Homebrew/cmd/reinstall.rb b/Library/Homebrew/cmd/reinstall.rb index 9c67de6062..094936dd3f 100644 --- a/Library/Homebrew/cmd/reinstall.rb +++ b/Library/Homebrew/cmd/reinstall.rb @@ -133,17 +133,7 @@ module Homebrew # Main block: if asking the user is enabled, show dependency and size information. if args.ask? - ohai "Looking for bottles..." - - sized_formulae = Install.compute_sized_formulae(formulae, args: args) - sizes = Install.compute_total_sizes(sized_formulae, debug: args.debug?) - - puts "Formulae: #{sized_formulae.join(", ")}\n\n" - puts "Download Size: #{disk_usage_readable(sizes[:download])}" - puts "Install Size: #{disk_usage_readable(sizes[:installed])}" - puts "Net Install Size: #{disk_usage_readable(sizes[:net])}" if sizes[:net] != 0 - - Install.ask_input + Install.ask(formulae, args: args) end formulae.each do |formula| diff --git a/Library/Homebrew/cmd/upgrade.rb b/Library/Homebrew/cmd/upgrade.rb index 4e1fac7a03..c33c7c7bf4 100644 --- a/Library/Homebrew/cmd/upgrade.rb +++ b/Library/Homebrew/cmd/upgrade.rb @@ -216,24 +216,14 @@ module Homebrew "#{f.full_specified_name} #{f.pkg_version}" end end - puts formulae_upgrades.join("\n") + puts formulae_upgrades.join("\n") unless args.ask? end Install.perform_preinstall_checks_once # Main block: if asking the user is enabled, show dependency and size information. if args.ask? - ohai "Looking for bottles..." - - sized_formulae = Install.compute_sized_formulae(formulae_to_install, args: args) - sizes = Install.compute_total_sizes(sized_formulae, debug: args.debug?) - - puts "Formulae: #{sized_formulae.join(", ")}\n\n" - puts "Download Size: #{disk_usage_readable(sizes[:download])}" - puts "Install Size: #{disk_usage_readable(sizes[:installed])}" - puts "Net Install Size: #{disk_usage_readable(sizes[:net])}" if sizes[:net] != 0 - - Install.ask_input + Install.ask(formulae_to_install, args: args) end Upgrade.upgrade_formulae( diff --git a/Library/Homebrew/install.rb b/Library/Homebrew/install.rb index 558d722737..37a42ccd3b 100644 --- a/Library/Homebrew/install.rb +++ b/Library/Homebrew/install.rb @@ -327,17 +327,74 @@ module Homebrew puts formula_names.join(" ") end + + # Main block: if asking the user is enabled, show dependency and size information. + def ask(formulae, args:) + ohai "Looking for bottles..." + + sized_formulae = compute_sized_formulae(formulae, args: args) + sizes = compute_total_sizes(sized_formulae, debug: args.debug?) + + puts "#{::Utils.pluralize("Formul", sized_formulae.count, plural: "ae", + singular: "a")} (#{sized_formulae.count}): #{sized_formulae.join(", ")}\n\n" + puts "Download Size: #{disk_usage_readable(sizes[:download])}" + puts "Install Size: #{disk_usage_readable(sizes[:installed])}" + puts "Net Install Size: #{disk_usage_readable(sizes[:net])}" if sizes[:net] != 0 + + ask_input + end + + private + + def perform_preinstall_checks(all_fatal: false) + check_prefix + check_cpu + attempt_directory_creation + Diagnostic.checks(:supported_configuration_checks, fatal: all_fatal) + Diagnostic.checks(:fatal_preinstall_checks) + end + alias generic_perform_preinstall_checks perform_preinstall_checks + + def attempt_directory_creation + Keg.must_exist_directories.each do |dir| + FileUtils.mkdir_p(dir) unless dir.exist? + rescue + nil + end + end + + def check_cpu + return unless Hardware::CPU.ppc? + + odie <<~EOS + Sorry, Homebrew does not support your computer's CPU architecture! + For PowerPC Mac (PPC32/PPC64BE) support, see: + #{Formatter.url("https://github.com/mistydemeo/tigerbrew")} + EOS + end + + def install_formula(formula_installer) + formula = formula_installer.formula + + upgrade = formula.linked? && formula.outdated? && !formula.head? && !Homebrew::EnvConfig.no_install_upgrade? + + Upgrade.install_formula(formula_installer, upgrade:) + end + + def ask_input ohai "Do you want to proceed with the installation? [Y/y/yes/N/n]" - return unless $stdin.gets != nil accepted_inputs = %w[y yes] declined_inputs = %w[n no] loop do - result = $stdin.gets.chomp.strip.downcase + result = $stdin.gets + return unless result + + result = result.chomp.strip.downcase if accepted_inputs.include?(result) break elsif declined_inputs.include?(result) - exit 0 + exit 1 else puts "Invalid input. Please enter 'Y', 'y', or 'yes' to proceed, or 'N' to abort." end @@ -359,7 +416,11 @@ module Homebrew outdated_dependents = deps.map(&:to_formula).reject(&:pinned?).select do |dep| dep.installed_kegs.empty? || (dep.bottled? && dep.outdated?) end - + deps.map(&:to_formula).each do |f| + outdated_dependents.concat(f.recursive_dependencies.map(&:to_formula).reject(&:pinned?).select do |dep| + dep.installed_kegs.empty? || (dep.bottled? && dep.outdated?) + end) + end formula_list.concat(outdated_dependents) end @@ -403,43 +464,6 @@ module Homebrew installed: total_installed_size, net: total_net_size } end - - private - - def perform_preinstall_checks(all_fatal: false) - check_prefix - check_cpu - attempt_directory_creation - Diagnostic.checks(:supported_configuration_checks, fatal: all_fatal) - Diagnostic.checks(:fatal_preinstall_checks) - end - alias generic_perform_preinstall_checks perform_preinstall_checks - - def attempt_directory_creation - Keg.must_exist_directories.each do |dir| - FileUtils.mkdir_p(dir) unless dir.exist? - rescue - nil - end - end - - def check_cpu - return unless Hardware::CPU.ppc? - - odie <<~EOS - Sorry, Homebrew does not support your computer's CPU architecture! - For PowerPC Mac (PPC32/PPC64BE) support, see: - #{Formatter.url("https://github.com/mistydemeo/tigerbrew")} - EOS - end - - def install_formula(formula_installer) - formula = formula_installer.formula - - upgrade = formula.linked? && formula.outdated? && !formula.head? && !Homebrew::EnvConfig.no_install_upgrade? - - Upgrade.install_formula(formula_installer, upgrade:) - end end end end