Skip to content

Commit b845b03

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 b845b03

7 files changed

Lines changed: 251 additions & 261 deletions

File tree

Library/Homebrew/cmd/install.rb

Lines changed: 18 additions & 4 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", {
@@ -326,8 +325,23 @@ def run
326325
dry_run: args.dry_run?,
327326
)
328327

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?
328+
# Main block: if asking the user is enabled, show dry-run information.
329+
if args.ask?
330+
Install.ask_formulae(
331+
formulae_installer,
332+
dependants,
333+
flags: args.flags_only,
334+
force_bottle: args.force_bottle?,
335+
build_from_source_formulae: args.build_from_source_formulae,
336+
interactive: args.interactive?,
337+
keep_tmp: args.keep_tmp?,
338+
debug_symbols: args.debug_symbols?,
339+
force: args.force?,
340+
debug: args.debug?,
341+
quiet: args.quiet?,
342+
verbose: args.verbose?,
343+
)
344+
end
331345

332346
if formulae_installer.any? && fetch_casks.empty? && !args.ask? && !args.dry_run? &&
333347
!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: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ def run
158158
prefetched_cask_names = T.let([], T::Array[String])
159159
prefetched_cask_upgrades = T.let([], T::Array[String])
160160
@final_upgrade_summary = T.let(FinalUpgradeSummary.new, T.nilable(FinalUpgradeSummary))
161+
@ask_prompt_required = T.let(false, T.nilable(T::Boolean))
161162

162163
if args.named.present?
163164
args.named.to_formulae_and_casks_and_unavailable(method: :resolve).each do |item|
@@ -207,7 +208,16 @@ def run
207208
end
208209

209210
show_final_upgrade_summary(dry_run: true)
210-
Install.ask(action: "upgrade") if final_upgrade_summary.version_changes.present?
211+
if Install.ask_prompt_needed?(
212+
planned_names: final_upgrade_summary.version_changes.map do |version_change|
213+
version_change.split.fetch(0)
214+
end,
215+
requested_names: formulae.map(&:full_name) + casks.map(&:full_name),
216+
force: @ask_prompt_required == true,
217+
named: args.named.present?,
218+
)
219+
Install.ask(action: "upgrade")
220+
end
211221
@final_upgrade_summary = FinalUpgradeSummary.new
212222
end
213223

@@ -579,6 +589,11 @@ def upgrade_outdated_formulae!(formulae, prefetch_only: false, use_prefetched: f
579589
end
580590

581591
record_formula_upgrade_summary(context, include_sizes: dry_run)
592+
if args.ask? && dry_run && args.named.present? &&
593+
Install.formulae_ask_prompt_needed?(context.formulae_installer, context.dependants)
594+
@ask_prompt_required = true
595+
end
596+
582597
skip_formula_names = if dry_run
583598
(context.formulae_installer.map(&:formula) + context.dependants.upgradeable)
584599
.uniq(&:full_name)

0 commit comments

Comments
 (0)