From 1416da262b526ecbf9543682b8a269dd98334d87 Mon Sep 17 00:00:00 2001 From: thibhero Date: Sat, 3 May 2025 15:23:20 -0400 Subject: [PATCH 1/6] returning if formulae is empty --- Library/Homebrew/install.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/Library/Homebrew/install.rb b/Library/Homebrew/install.rb index f001f41578..52e1fbb2da 100644 --- a/Library/Homebrew/install.rb +++ b/Library/Homebrew/install.rb @@ -332,6 +332,7 @@ module Homebrew # If asking the user is enabled, show dependency and size information. def ask(formulae, args:) + return if formulae.empty? ohai "Looking for bottles..." sized_formulae = compute_sized_formulae(formulae, args: args) From 96ca8d2e07767e8f3cdc1106b5bd779e636f37de Mon Sep 17 00:00:00 2001 From: thibhero Date: Sat, 3 May 2025 15:23:42 -0400 Subject: [PATCH 2/6] displaying a warning if ask is used with casks --- Library/Homebrew/cmd/install.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Library/Homebrew/cmd/install.rb b/Library/Homebrew/cmd/install.rb index c4125ba426..14c662c68e 100644 --- a/Library/Homebrew/cmd/install.rb +++ b/Library/Homebrew/cmd/install.rb @@ -218,6 +218,9 @@ module Homebrew end if casks.any? + if args.options_only.include? "--ask" + opoo "Option --ask is not compatible with casks." + end 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)}:" From 5013c17474b5921eab268330bee999818f919d75 Mon Sep 17 00:00:00 2001 From: thibhero Date: Sat, 3 May 2025 15:39:43 -0400 Subject: [PATCH 3/6] formatting correctly with `brew style` --- Library/Homebrew/cmd/install.rb | 4 +--- Library/Homebrew/install.rb | 1 + 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/cmd/install.rb b/Library/Homebrew/cmd/install.rb index 14c662c68e..b369b7fc28 100644 --- a/Library/Homebrew/cmd/install.rb +++ b/Library/Homebrew/cmd/install.rb @@ -218,9 +218,7 @@ module Homebrew end if casks.any? - if args.options_only.include? "--ask" - opoo "Option --ask is not compatible with casks." - end + opoo "Option --ask is not compatible with casks." if args.options_only.include? "--ask" 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)}:" diff --git a/Library/Homebrew/install.rb b/Library/Homebrew/install.rb index 52e1fbb2da..f181023614 100644 --- a/Library/Homebrew/install.rb +++ b/Library/Homebrew/install.rb @@ -333,6 +333,7 @@ module Homebrew # If asking the user is enabled, show dependency and size information. def ask(formulae, args:) return if formulae.empty? + ohai "Looking for bottles..." sized_formulae = compute_sized_formulae(formulae, args: args) From f875dbc8a7e9d4c35f71636b125097bd4a6509b8 Mon Sep 17 00:00:00 2001 From: thibhero Date: Wed, 7 May 2025 12:07:29 -0400 Subject: [PATCH 4/6] Implementing ask input with casks renamed `ask` to `ask_formulae` moving option `--ask` to work with formulae and casks --- Library/Homebrew/cmd/install.rb | 13 ++++++------- Library/Homebrew/cmd/reinstall.rb | 14 ++++++++------ Library/Homebrew/cmd/upgrade.rb | 14 +++++++------- Library/Homebrew/install.rb | 13 +++++++++++-- 4 files changed, 32 insertions(+), 22 deletions(-) diff --git a/Library/Homebrew/cmd/install.rb b/Library/Homebrew/cmd/install.rb index b369b7fc28..b49ff52289 100644 --- a/Library/Homebrew/cmd/install.rb +++ b/Library/Homebrew/cmd/install.rb @@ -43,6 +43,10 @@ module Homebrew description: "Print the verification and post-install steps." switch "-n", "--dry-run", description: "Show what would be installed, but do not actually install anything." + switch "--ask", + env: :ask, + description: "Ask for confirmation before downloading and installing formulae. " \ + "Print bottles and dependencies download size and install size." [ [:switch, "--formula", "--formulae", { description: "Treat all named arguments as formulae.", @@ -123,11 +127,6 @@ module Homebrew [:switch, "--overwrite", { description: "Delete files that already exist in the prefix while linking.", }], - [:switch, "--ask", { - description: "Ask for confirmation before downloading and installing formulae. " \ - "Print bottles and dependencies download size and install size.", - env: :ask, - }], ].each do |args| options = args.pop send(*args, **options) @@ -218,7 +217,7 @@ module Homebrew end if casks.any? - opoo "Option --ask is not compatible with casks." if args.options_only.include? "--ask" + Install.ask_casks casks if args.ask? 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)}:" @@ -311,7 +310,7 @@ module Homebrew Install.perform_preinstall_checks_once Install.check_cc_argv(args.cc) - Install.ask(formulae, args: args) if args.ask? + Install.ask_formulae(formulae, args: args) if args.ask? Install.install_formulae( installed_formulae, diff --git a/Library/Homebrew/cmd/reinstall.rb b/Library/Homebrew/cmd/reinstall.rb index 3c767f0619..3774c72390 100644 --- a/Library/Homebrew/cmd/reinstall.rb +++ b/Library/Homebrew/cmd/reinstall.rb @@ -39,6 +39,10 @@ module Homebrew "non-migrated versions." switch "-v", "--verbose", description: "Print the verification and post-install steps." + switch "--ask", + description: "Ask for confirmation before downloading and upgrading formulae. " \ + "Print bottles and dependencies download size, install and net install size.", + env: :ask [ [:switch, "--formula", "--formulae", { description: "Treat all named arguments as formulae." }], [:switch, "-s", "--build-from-source", { @@ -63,11 +67,6 @@ module Homebrew [:switch, "-g", "--git", { description: "Create a Git repository, useful for creating patches to the software.", }], - [: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| options = args.pop send(*args, **options) @@ -132,7 +131,7 @@ module Homebrew Install.perform_preinstall_checks_once # If asking the user is enabled, show dependency and size information. - Install.ask(formulae, args: args) if args.ask? + Install.ask_formulae(formulae, args: args) if args.ask? formulae.each do |formula| if formula.pinned? @@ -173,6 +172,9 @@ module Homebrew end if casks.any? + if args.ask? + Install.ask_casks casks + end Cask::Reinstall.reinstall_casks( *casks, binaries: args.binaries?, diff --git a/Library/Homebrew/cmd/upgrade.rb b/Library/Homebrew/cmd/upgrade.rb index b48ace323d..a6b5172489 100644 --- a/Library/Homebrew/cmd/upgrade.rb +++ b/Library/Homebrew/cmd/upgrade.rb @@ -39,7 +39,11 @@ module Homebrew description: "Print the verification and post-install steps." switch "-n", "--dry-run", description: "Show what would be upgraded, but do not actually upgrade anything." - [ + switch "--ask", + description: "Ask for confirmation before downloading and upgrading formulae. " \ + "Print bottles and dependencies download size, install and net install size.", + env: :ask + [ [:switch, "--formula", "--formulae", { description: "Treat all named arguments as formulae. If no named arguments " \ "are specified, upgrade only outdated formulae.", @@ -71,11 +75,6 @@ module Homebrew [:switch, "--overwrite", { 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| options = args.pop send(*args, **options) @@ -222,7 +221,7 @@ module Homebrew Install.perform_preinstall_checks_once # Main block: if asking the user is enabled, show dependency and size information. - Install.ask(formulae_to_install, args: args) if args.ask? + Install.ask_formulae(formulae_to_install, args: args) if args.ask? Upgrade.upgrade_formulae( formulae_to_install, @@ -261,6 +260,7 @@ module Homebrew sig { params(casks: T::Array[Cask::Cask]).returns(T::Boolean) } def upgrade_outdated_casks(casks) return false if args.formula? + Install.ask_casks casks Cask::Upgrade.upgrade_casks( *casks, diff --git a/Library/Homebrew/install.rb b/Library/Homebrew/install.rb index f181023614..c93a0f7610 100644 --- a/Library/Homebrew/install.rb +++ b/Library/Homebrew/install.rb @@ -331,8 +331,8 @@ module Homebrew end # If asking the user is enabled, show dependency and size information. - def ask(formulae, args:) - return if formulae.empty? + def ask_formulae(formulae, args:) + return if formulae.empty? && casks.empty? ohai "Looking for bottles..." @@ -348,6 +348,15 @@ module Homebrew ask_input end + def ask_casks(casks) + return if casks.empty? + + puts "#{::Utils.pluralize("Cask", casks.count, plural: "s")} \ +(#{casks.count}): #{casks.join(", ")}\n\n" + + ask_input + end + private def perform_preinstall_checks(all_fatal: false) From 499a9b9dae31601b74f775683c3266ca3b8ed17b Mon Sep 17 00:00:00 2001 From: thibhero Date: Wed, 7 May 2025 12:08:46 -0400 Subject: [PATCH 5/6] changing to installed_formulae, as its checked if it should be installed --- Library/Homebrew/cmd/install.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/cmd/install.rb b/Library/Homebrew/cmd/install.rb index b49ff52289..517414f9fe 100644 --- a/Library/Homebrew/cmd/install.rb +++ b/Library/Homebrew/cmd/install.rb @@ -310,7 +310,7 @@ module Homebrew Install.perform_preinstall_checks_once Install.check_cc_argv(args.cc) - Install.ask_formulae(formulae, args: args) if args.ask? + Install.ask_formulae(installed_formulae, args: args) if args.ask? Install.install_formulae( installed_formulae, From 76e7a133326d72f128769cf2f79f2c4387081ff9 Mon Sep 17 00:00:00 2001 From: thibhero Date: Wed, 7 May 2025 12:29:32 -0400 Subject: [PATCH 6/6] applying `brew tests, typecheck, style` --- Library/Homebrew/cmd/reinstall.rb | 4 +--- Library/Homebrew/cmd/upgrade.rb | 3 ++- Library/Homebrew/install.rb | 2 +- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/Library/Homebrew/cmd/reinstall.rb b/Library/Homebrew/cmd/reinstall.rb index 3774c72390..2c1208e54a 100644 --- a/Library/Homebrew/cmd/reinstall.rb +++ b/Library/Homebrew/cmd/reinstall.rb @@ -172,9 +172,7 @@ module Homebrew end if casks.any? - if args.ask? - Install.ask_casks casks - end + Install.ask_casks casks if args.ask? Cask::Reinstall.reinstall_casks( *casks, binaries: args.binaries?, diff --git a/Library/Homebrew/cmd/upgrade.rb b/Library/Homebrew/cmd/upgrade.rb index a6b5172489..7e053982e0 100644 --- a/Library/Homebrew/cmd/upgrade.rb +++ b/Library/Homebrew/cmd/upgrade.rb @@ -43,7 +43,7 @@ module Homebrew description: "Ask for confirmation before downloading and upgrading formulae. " \ "Print bottles and dependencies download size, install and net install size.", env: :ask - [ + [ [:switch, "--formula", "--formulae", { description: "Treat all named arguments as formulae. If no named arguments " \ "are specified, upgrade only outdated formulae.", @@ -260,6 +260,7 @@ module Homebrew sig { params(casks: T::Array[Cask::Cask]).returns(T::Boolean) } def upgrade_outdated_casks(casks) return false if args.formula? + Install.ask_casks casks Cask::Upgrade.upgrade_casks( diff --git a/Library/Homebrew/install.rb b/Library/Homebrew/install.rb index c93a0f7610..8fba7fabf7 100644 --- a/Library/Homebrew/install.rb +++ b/Library/Homebrew/install.rb @@ -332,7 +332,7 @@ module Homebrew # If asking the user is enabled, show dependency and size information. def ask_formulae(formulae, args:) - return if formulae.empty? && casks.empty? + return if formulae.empty? ohai "Looking for bottles..."