Skip to content

Commit b0af8d5

Browse files
committed
Align ask dry-run prompts
- Use dry-run-style `--ask` plans for install and reinstall commands. - Make single-package operations proceed without a prompt e.g. if you `brew install foo` and there's no dependencies or dependents to install: just install without the prompt. - Keep prompting when dependencies or dependents change the plan.
1 parent 1f29e9c commit b0af8d5

7 files changed

Lines changed: 296 additions & 275 deletions

File tree

Library/Homebrew/cmd/install.rb

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ class InstallCmd < AbstractCommand
4747
description: "Show what would be installed, but do not actually install anything."
4848
switch "--ask",
4949
description: "Ask for confirmation before downloading and installing. " \
50-
"Print a dependency plan, including added, changed and removed packages " \
51-
"and dependencies, with download and install sizes of formula bottles.",
50+
"Print the same plan as `--dry-run` before prompting.",
5251
env: :ask
5352
[
5453
[:switch, "--formula", "--formulae", {
@@ -217,21 +216,7 @@ def run
217216
fetch_casks = T.let([], T::Array[Cask::Cask])
218217
if casks.any?
219218
if args.dry_run?
220-
if (casks_to_install = casks.reject(&:installed?).presence)
221-
ohai "Would install #{::Utils.pluralize("cask", casks_to_install.count, include_count: true)}:"
222-
puts casks_to_install.map(&:full_name).join(" ")
223-
end
224-
casks.each do |cask|
225-
dep_names = CaskDependent.new(cask)
226-
.runtime_dependencies
227-
.reject(&:installed?)
228-
.map(&:name)
229-
next if dep_names.blank?
230-
231-
ohai "Would install #{::Utils.pluralize("dependency", dep_names.count, include_count: true)} " \
232-
"for #{cask.full_name}:"
233-
puts dep_names.join(" ")
234-
end
219+
Install.print_dry_run_casks(casks, skip_cask_deps: args.skip_cask_deps?, include_installed: false)
235220
return
236221
end
237222

@@ -326,8 +311,23 @@ def run
326311
dry_run: args.dry_run?,
327312
)
328313

329-
# Main block: if asking the user is enabled, show dependency and size information.
330-
Install.ask_formulae(formulae_installer, dependants, args: args) if args.ask?
314+
# Main block: if asking the user is enabled, show dry-run information.
315+
if args.ask?
316+
Install.ask_formulae(
317+
formulae_installer,
318+
dependants,
319+
flags: args.flags_only,
320+
force_bottle: args.force_bottle?,
321+
build_from_source_formulae: args.build_from_source_formulae,
322+
interactive: args.interactive?,
323+
keep_tmp: args.keep_tmp?,
324+
debug_symbols: args.debug_symbols?,
325+
force: args.force?,
326+
debug: args.debug?,
327+
quiet: args.quiet?,
328+
verbose: args.verbose?,
329+
)
330+
end
331331

332332
if formulae_installer.any? && fetch_casks.empty? && !args.ask? && !args.dry_run? &&
333333
!Homebrew::EnvConfig.no_env_hints?

Library/Homebrew/cmd/reinstall.rb

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ class Reinstall < AbstractCommand
4040
description: "Print the verification and post-install steps."
4141
switch "--ask",
4242
description: "Ask for confirmation before downloading and reinstalling. " \
43-
"Print a dependency plan, including added, changed and removed packages " \
44-
"and dependencies, with download and install sizes of formula bottles.",
43+
"Print what would be reinstalled before prompting.",
4544
env: :ask
4645
[
4746
[:switch, "--formula", "--formulae", {
@@ -200,8 +199,24 @@ def run
200199

201200
formulae_installers = reinstall_contexts.map(&:formula_installer)
202201

203-
# Main block: if asking the user is enabled, show dependency and size information.
204-
Install.ask_formulae(formulae_installers, dependants, action: "reinstallation", args: args) if args.ask?
202+
# Main block: if asking the user is enabled, show dry-run information.
203+
if args.ask?
204+
Install.ask_formulae(
205+
formulae_installers,
206+
dependants,
207+
action: "reinstallation",
208+
flags: args.flags_only,
209+
force_bottle: args.force_bottle?,
210+
build_from_source_formulae: args.build_from_source_formulae,
211+
interactive: args.interactive?,
212+
keep_tmp: args.keep_tmp?,
213+
debug_symbols: args.debug_symbols?,
214+
force: args.force?,
215+
debug: args.debug?,
216+
quiet: args.quiet?,
217+
verbose: args.verbose?,
218+
)
219+
end
205220

206221
valid_formula_installers = if casks.any?
207222
shared_download_queue = Homebrew::DownloadQueue.new(pour: true)

Library/Homebrew/cmd/upgrade.rb

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,12 @@ class FinalUpgradeSummary < T::Struct
140140
named_args [:installed_formula, :installed_cask]
141141
end
142142

143+
sig { override.params(argv: T::Array[String]).void }
144+
def initialize(argv = ARGV.freeze)
145+
super
146+
@ask_prompt_required = T.let(false, T::Boolean)
147+
end
148+
143149
sig { override.void }
144150
def run
145151
if args.build_from_source? && args.named.empty?
@@ -158,6 +164,7 @@ def run
158164
prefetched_cask_names = T.let([], T::Array[String])
159165
prefetched_cask_upgrades = T.let([], T::Array[String])
160166
@final_upgrade_summary = T.let(FinalUpgradeSummary.new, T.nilable(FinalUpgradeSummary))
167+
@ask_prompt_required = false
161168

162169
if args.named.present?
163170
args.named.to_formulae_and_casks_and_unavailable(method: :resolve).each do |item|
@@ -207,7 +214,16 @@ def run
207214
end
208215

209216
show_final_upgrade_summary(dry_run: true)
210-
Install.ask(action: "upgrade") if final_upgrade_summary.version_changes.present?
217+
if Install.ask_prompt_needed?(
218+
planned_names: final_upgrade_summary.version_changes.map do |version_change|
219+
version_change.split.fetch(0)
220+
end,
221+
requested_names: formulae.map(&:full_name) + casks.map(&:full_name),
222+
force: @ask_prompt_required,
223+
named: args.named.present?,
224+
)
225+
Install.ask(action: "upgrade")
226+
end
211227
@final_upgrade_summary = FinalUpgradeSummary.new
212228
end
213229

@@ -579,6 +595,11 @@ def upgrade_outdated_formulae!(formulae, prefetch_only: false, use_prefetched: f
579595
end
580596

581597
record_formula_upgrade_summary(context, include_sizes: dry_run)
598+
if args.ask? && dry_run && args.named.present? &&
599+
Install.formulae_ask_prompt_needed?(context.formulae_installer, context.dependants)
600+
@ask_prompt_required = true
601+
end
602+
582603
skip_formula_names = if dry_run
583604
(context.formulae_installer.map(&:formula) + context.dependants.upgradeable)
584605
.uniq(&:full_name)

0 commit comments

Comments
 (0)