diff --git a/lib/bundle/brew_installer.rb b/lib/bundle/brew_installer.rb index f4bd2c10a..c21f4a553 100644 --- a/lib/bundle/brew_installer.rb +++ b/lib/bundle/brew_installer.rb @@ -121,7 +121,7 @@ def link_change_state!(verbose: false) verb = "#{cmd}ing".capitalize with_args = " with #{link_args.join(" ")}" if link_args.present? puts "#{verb} #{@name} formula#{with_args}." if verbose - return Bundle.system(HOMEBREW_BREW_FILE, cmd, *link_args, @name, verbose:) + return Bundle.brew(cmd, *link_args, @name, verbose:) end true @@ -226,7 +226,7 @@ def resolve_conflicts!(verbose:) It is currently installed and conflicts with #{@name}. EOS end - return false unless Bundle.system(HOMEBREW_BREW_FILE, "unlink", conflict, verbose:) + return false unless Bundle.brew("unlink", conflict, verbose:) if restart_service? puts "Stopping #{conflict} service (if it is running)." if verbose @@ -242,7 +242,7 @@ def install!(verbose:, force:) install_args << "--force" << "--overwrite" if force with_args = " with #{install_args.join(" ")}" if install_args.present? puts "Installing #{@name} formula#{with_args}. It is not currently installed." if verbose - unless Bundle.system(HOMEBREW_BREW_FILE, "install", "--formula", @full_name, *install_args, verbose:) + unless Bundle.brew("install", "--formula", @full_name, *install_args, verbose:) @changed = nil return false end @@ -257,7 +257,7 @@ def upgrade!(verbose:, force:) upgrade_args << "--force" if force with_args = " with #{upgrade_args.join(" ")}" if upgrade_args.present? puts "Upgrading #{@name} formula#{with_args}. It is installed but not up-to-date." if verbose - unless Bundle.system(HOMEBREW_BREW_FILE, "upgrade", "--formula", @name, *upgrade_args, verbose:) + unless Bundle.brew("upgrade", "--formula", @name, *upgrade_args, verbose:) @changed = nil return false end diff --git a/lib/bundle/brew_services.rb b/lib/bundle/brew_services.rb index 2d731c343..cd31f5363 100644 --- a/lib/bundle/brew_services.rb +++ b/lib/bundle/brew_services.rb @@ -11,21 +11,21 @@ def reset! def stop(name, verbose: false) return true unless started?(name) - return unless Bundle.system HOMEBREW_BREW_FILE, "services", "stop", name, verbose: verbose + return unless Bundle.brew("services", "stop", name, verbose:) started_services.delete(name) true end def start(name, verbose: false) - return unless Bundle.system HOMEBREW_BREW_FILE, "services", "start", name, verbose: verbose + return unless Bundle.brew("services", "start", name, verbose:) started_services << name true end def restart(name, verbose: false) - return unless Bundle.system HOMEBREW_BREW_FILE, "services", "restart", name, verbose: verbose + return unless Bundle.brew("services", "restart", name, verbose:) started_services << name true diff --git a/lib/bundle/bundle.rb b/lib/bundle/bundle.rb index 5d4ed0d69..ff1af098a 100644 --- a/lib/bundle/bundle.rb +++ b/lib/bundle/bundle.rb @@ -21,6 +21,10 @@ def system(cmd, *args, verbose: false) success end + def brew(*args, verbose: false) + system(HOMEBREW_BREW_FILE, *args, verbose:) + end + def mas_installed? @mas_installed ||= which_formula("mas") end diff --git a/lib/bundle/cask_installer.rb b/lib/bundle/cask_installer.rb index 29afa959f..2f0dd653d 100644 --- a/lib/bundle/cask_installer.rb +++ b/lib/bundle/cask_installer.rb @@ -34,7 +34,7 @@ def install(name, preinstall: true, no_upgrade: false, verbose: false, force: fa if installed_casks.include?(name) && upgrading?(no_upgrade, name, options) status = "#{options[:greedy] ? "may not be" : "not"} up-to-date" puts "Upgrading #{name} cask. It is installed but #{status}." if verbose - return Bundle.system HOMEBREW_BREW_FILE, "upgrade", "--cask", full_name, verbose: + return Bundle.brew("upgrade", "--cask", full_name, verbose:) end args = options.fetch(:args, []).filter_map do |k, v| @@ -54,7 +54,7 @@ def install(name, preinstall: true, no_upgrade: false, verbose: false, force: fa with_args = " with #{args.join(" ")}" if args.present? puts "Installing #{name} cask#{with_args}. It is not currently installed." if verbose - return false unless Bundle.system HOMEBREW_BREW_FILE, "install", "--cask", full_name, *args, verbose: verbose + return false unless Bundle.brew("install", "--cask", full_name, *args, verbose:) installed_casks << name true diff --git a/lib/bundle/mac_app_store_installer.rb b/lib/bundle/mac_app_store_installer.rb index 2125b32b0..1213f50a7 100644 --- a/lib/bundle/mac_app_store_installer.rb +++ b/lib/bundle/mac_app_store_installer.rb @@ -14,7 +14,7 @@ def reset! def preinstall(name, id, no_upgrade: false, verbose: false) unless Bundle.mas_installed? puts "Installing mas. It is not currently installed." if verbose - Bundle.system(HOMEBREW_BREW_FILE, "install", "mas", verbose:) + Bundle.brew("install", "mas", verbose:) raise "Unable to install #{name} app. mas installation failed." unless Bundle.mas_installed? end diff --git a/lib/bundle/tap_installer.rb b/lib/bundle/tap_installer.rb index fc13b0b69..352c15436 100644 --- a/lib/bundle/tap_installer.rb +++ b/lib/bundle/tap_installer.rb @@ -22,9 +22,9 @@ def install(name, preinstall: true, verbose: false, force: false, **options) args.append("--force-auto-update") if options[:force_auto_update] success = if options[:clone_target] - Bundle.system(HOMEBREW_BREW_FILE, "tap", name, options[:clone_target], *args, verbose:) + Bundle.brew("tap", name, options[:clone_target], *args, verbose:) else - Bundle.system(HOMEBREW_BREW_FILE, "tap", name, *args, verbose:) + Bundle.brew("tap", name, *args, verbose:) end unless success diff --git a/lib/bundle/vscode_extension_installer.rb b/lib/bundle/vscode_extension_installer.rb index caa4d6cf3..e41866bb5 100644 --- a/lib/bundle/vscode_extension_installer.rb +++ b/lib/bundle/vscode_extension_installer.rb @@ -11,7 +11,7 @@ def reset! def preinstall(name, no_upgrade: false, verbose: false) if !Bundle.vscode_installed? && Bundle.cask_installed? puts "Installing visual-studio-code. It is not currently installed." if verbose - Bundle.system HOMEBREW_BREW_FILE, "install", "--cask", "visual-studio-code", verbose: + Bundle.brew("install", "--cask", "visual-studio-code", verbose:) end if extension_installed?(name) diff --git a/lib/bundle/whalebrew_installer.rb b/lib/bundle/whalebrew_installer.rb index 123c7aad9..612b2f886 100644 --- a/lib/bundle/whalebrew_installer.rb +++ b/lib/bundle/whalebrew_installer.rb @@ -11,7 +11,7 @@ def reset! def preinstall(name, verbose: false, **_options) unless Bundle.whalebrew_installed? puts "Installing whalebrew. It is not currently installed." if verbose - Bundle.system(HOMEBREW_BREW_FILE, "install", "--formula", "whalebrew", verbose:) + Bundle.brew("install", "--formula", "whalebrew", verbose:) raise "Unable to install #{name} app. Whalebrew installation failed." unless Bundle.whalebrew_installed? end