adding the --ask option for the upgrade command

This commit is contained in:
thibhero 2025-02-09 20:47:35 -05:00
parent 49999e8727
commit 92470e0028
4 changed files with 73 additions and 0 deletions

View File

@ -71,6 +71,11 @@ module Homebrew
[:switch, "--overwrite", { [:switch, "--overwrite", {
description: "Delete files that already exist in the prefix while linking.", description: "Delete files that already exist in the prefix while linking.",
}], }],
[:switch, "--ask", {
description: "Ask for confirmation before downloading and upgrading formulae. " \
"Print bottles and dependencies download size, install and net install size.",
env: :ask,
}],
].each do |args| ].each do |args|
options = args.pop options = args.pop
send(*args, **options) send(*args, **options)
@ -216,6 +221,64 @@ module Homebrew
Install.perform_preinstall_checks_once Install.perform_preinstall_checks_once
ask_input = lambda {
ohai "Do you want to proceed with the installation? [Y/y/yes/N/n]"
accepted_inputs = %w[y yes]
declined_inputs = %w[n no]
loop do
result = $stdin.gets.chomp.strip.downcase
if accepted_inputs.include?(result)
puts "Proceeding with installation..."
break
elsif declined_inputs.include?(result)
return
else
puts "Invalid input. Please enter 'Y', 'y', or 'yes' to proceed, or 'N' to abort."
end
end
}
# Showing dependencies and required size to install
if args.ask?
ohai "Looking for bottles..."
sized_formulae = []
total_download_size = 0
total_installed_size = 0
total_net_size = 0
formulae_to_install.each do |f|
next unless (bottle = f.bottle)
kegs_size = 0
# keep it quiet as there could be a lot of json fetch, its not intuitive to show them all.
bottle.fetch_tab(quiet: !args.debug?)
total_download_size += T.must(bottle.bottle_size) if bottle.bottle_size
total_installed_size += T.must(bottle.installed_size) if bottle.installed_size
f.installed_kegs.each do |keg|
kegs_size += keg.disk_usage if keg.disk_usage
end
total_net_size += (bottle.installed_size - kegs_size) if bottle.installed_size
sized_formulae.push(f)
next if f.deps.empty?
# f.recursive_dependencies.each do |dep|
# f_dep = dep.to_formula
# kegs_dep_size = 0
# bottle_dep = f_dep.bottle
# bottle_dep.fetch_tab(quiet: !args.debug?)
# total_download_size += bottle_dep.bottle_size if bottle_dep.bottle_size
# total_installed_size += bottle_dep.installed_size if bottle_dep.installed_size
# f_dep.installed_kegs.each do |keg|
# kegs_dep_size += keg.disk_usage if keg.disk_usage
# end
# total_net_size += (bottle_dep.installed_size - kegs_dep_size) if bottle_dep.installed_size
# end
end
puts "Formulae: #{sized_formulae.join(", ")}\n\n"
puts "Download Size: #{disk_usage_readable(total_download_size)}" if total_download_size
puts "Install Size: #{disk_usage_readable(total_installed_size)}\n" if total_installed_size
puts "Net Install Size: #{disk_usage_readable(total_net_size)}\n" if total_net_size
ask_input.call
end
Upgrade.upgrade_formulae( Upgrade.upgrade_formulae(
formulae_to_install, formulae_to_install,
flags: args.flags_only, flags: args.flags_only,

View File

@ -48,6 +48,10 @@ module Homebrew
"trying any other/default URLs.", "trying any other/default URLs.",
boolean: true, boolean: true,
}, },
HOMEBREW_ASK: {
description: "If set, pass `--ask`to all formula install commands.",
boolean: true,
},
HOMEBREW_AUTO_UPDATE_SECS: { HOMEBREW_AUTO_UPDATE_SECS: {
description: "Run `brew update` once every `$HOMEBREW_AUTO_UPDATE_SECS` seconds before some commands, " \ description: "Run `brew update` once every `$HOMEBREW_AUTO_UPDATE_SECS` seconds before some commands, " \
"e.g. `brew install`, `brew upgrade` and `brew tap`. Alternatively, " \ "e.g. `brew install`, `brew upgrade` and `brew tap`. Alternatively, " \

View File

@ -14,6 +14,9 @@ class Homebrew::Cmd::UpgradeCmd::Args < Homebrew::CLI::Args
sig { returns(T.nilable(String)) } sig { returns(T.nilable(String)) }
def appdir; end def appdir; end
sig { returns(T::Boolean) }
def ask?; end
sig { returns(T.nilable(String)) } sig { returns(T.nilable(String)) }
def audio_unit_plugindir; end def audio_unit_plugindir; end

View File

@ -28,6 +28,9 @@ module Homebrew::EnvConfig
sig { returns(T::Boolean) } sig { returns(T::Boolean) }
def artifact_domain_no_fallback?; end def artifact_domain_no_fallback?; end
sig { returns(T::Boolean) }
def ask?; end
sig { returns(T.nilable(::String)) } sig { returns(T.nilable(::String)) }
def auto_update_secs; end def auto_update_secs; end