Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 19 additions & 19 deletions Library/Homebrew/cmd/install.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ class InstallCmd < AbstractCommand
description: "Show what would be installed, but do not actually install anything."
switch "--ask",
description: "Ask for confirmation before downloading and installing. " \
"Print a dependency plan, including added, changed and removed packages " \
"and dependencies, with download and install sizes of formula bottles.",
"Print the same plan as `--dry-run` before prompting.",
env: :ask
[
[:switch, "--formula", "--formulae", {
Expand Down Expand Up @@ -217,21 +216,7 @@ def run
fetch_casks = T.let([], T::Array[Cask::Cask])
if casks.any?
if args.dry_run?
if (casks_to_install = casks.reject(&:installed?).presence)
ohai "Would install #{::Utils.pluralize("cask", casks_to_install.count, include_count: true)}:"
puts casks_to_install.map(&:full_name).join(" ")
end
casks.each do |cask|
dep_names = CaskDependent.new(cask)
.runtime_dependencies
.reject(&:installed?)
.map(&:name)
next if dep_names.blank?

ohai "Would install #{::Utils.pluralize("dependency", dep_names.count, include_count: true)} " \
"for #{cask.full_name}:"
puts dep_names.join(" ")
end
Install.print_dry_run_casks(casks, skip_cask_deps: args.skip_cask_deps?, include_installed: false)
return
end

Expand Down Expand Up @@ -326,8 +311,23 @@ def run
dry_run: args.dry_run?,
)

# Main block: if asking the user is enabled, show dependency and size information.
Install.ask_formulae(formulae_installer, dependants, args: args) if args.ask?
# Main block: if asking the user is enabled, show dry-run information.
if args.ask?
Install.ask_formulae(
formulae_installer,
dependants,
flags: args.flags_only,
force_bottle: args.force_bottle?,
build_from_source_formulae: args.build_from_source_formulae,
interactive: args.interactive?,
keep_tmp: args.keep_tmp?,
debug_symbols: args.debug_symbols?,
force: args.force?,
debug: args.debug?,
quiet: args.quiet?,
verbose: args.verbose?,
)
end

if formulae_installer.any? && fetch_casks.empty? && !args.ask? && !args.dry_run? &&
!Homebrew::EnvConfig.no_env_hints?
Expand Down
23 changes: 19 additions & 4 deletions Library/Homebrew/cmd/reinstall.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ class Reinstall < AbstractCommand
description: "Print the verification and post-install steps."
switch "--ask",
description: "Ask for confirmation before downloading and reinstalling. " \
"Print a dependency plan, including added, changed and removed packages " \
"and dependencies, with download and install sizes of formula bottles.",
"Print what would be reinstalled before prompting.",
env: :ask
[
[:switch, "--formula", "--formulae", {
Expand Down Expand Up @@ -200,8 +199,24 @@ def run

formulae_installers = reinstall_contexts.map(&:formula_installer)

# Main block: if asking the user is enabled, show dependency and size information.
Install.ask_formulae(formulae_installers, dependants, action: "reinstallation", args: args) if args.ask?
# Main block: if asking the user is enabled, show dry-run information.
if args.ask?
Install.ask_formulae(
formulae_installers,
dependants,
action: "reinstallation",
flags: args.flags_only,
force_bottle: args.force_bottle?,
build_from_source_formulae: args.build_from_source_formulae,
interactive: args.interactive?,
keep_tmp: args.keep_tmp?,
debug_symbols: args.debug_symbols?,
force: args.force?,
debug: args.debug?,
quiet: args.quiet?,
verbose: args.verbose?,
)
end

valid_formula_installers = if casks.any?
shared_download_queue = Homebrew::DownloadQueue.new(pour: true)
Expand Down
24 changes: 23 additions & 1 deletion Library/Homebrew/cmd/upgrade.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,12 @@ class FinalUpgradeSummary < T::Struct
named_args [:installed_formula, :installed_cask]
end

sig { override.params(argv: T::Array[String]).void }
def initialize(argv = ARGV.freeze)
super
@ask_prompt_required = T.let(false, T::Boolean)
end

sig { override.void }
def run
if args.build_from_source? && args.named.empty?
Expand All @@ -158,6 +164,7 @@ def run
prefetched_cask_names = T.let([], T::Array[String])
prefetched_cask_upgrades = T.let([], T::Array[String])
@final_upgrade_summary = T.let(FinalUpgradeSummary.new, T.nilable(FinalUpgradeSummary))
@ask_prompt_required = false

if args.named.present?
args.named.to_formulae_and_casks_and_unavailable(method: :resolve).each do |item|
Expand Down Expand Up @@ -207,7 +214,17 @@ def run
end

show_final_upgrade_summary(dry_run: true)
Install.ask(action: "upgrade") if final_upgrade_summary.version_changes.present?
if Install.ask_prompt_needed?(
planned_names: final_upgrade_summary.version_changes.map do |version_change|
planned_name = version_change.split.fetch(0)
formulae.find { |formula| formula.full_specified_name == planned_name }&.full_name || planned_name
end,
requested_names: args.named,
force: @ask_prompt_required,
named: args.named.present?,
)
Install.ask(action: "upgrade")
end
@final_upgrade_summary = FinalUpgradeSummary.new
end

Expand Down Expand Up @@ -579,6 +596,11 @@ def upgrade_outdated_formulae!(formulae, prefetch_only: false, use_prefetched: f
end

record_formula_upgrade_summary(context, include_sizes: dry_run)
if args.ask? && dry_run && args.named.present? &&
Install.formulae_ask_prompt_needed?(context.formulae_installer, context.dependants)
@ask_prompt_required = true
end

skip_formula_names = if dry_run
(context.formulae_installer.map(&:formula) + context.dependants.upgradeable)
.uniq(&:full_name)
Expand Down
Loading
Loading