Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve shelling out to brew #1551

Merged
merged 1 commit into from
Jan 7, 2025
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
8 changes: 4 additions & 4 deletions lib/bundle/brew_installer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions lib/bundle/brew_services.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions lib/bundle/bundle.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/bundle/cask_installer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/bundle/mac_app_store_installer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions lib/bundle/tap_installer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/bundle/vscode_extension_installer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion lib/bundle/whalebrew_installer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading