bundle: add --services flag for sh and exec

This commit is contained in:
Bo Anderson 2025-03-27 06:12:10 +00:00
parent 786ad348a5
commit c7e8b66da3
No known key found for this signature in database
4 changed files with 25 additions and 3 deletions

View File

@ -47,7 +47,7 @@ module Homebrew
PATH_LIKE_ENV_REGEX = /.+#{File::PATH_SEPARATOR}/ PATH_LIKE_ENV_REGEX = /.+#{File::PATH_SEPARATOR}/
def self.run(*args, global: false, file: nil, subcommand: "") def self.run(*args, global: false, file: nil, subcommand: "", services: false)
# Cleanup Homebrew's global environment # Cleanup Homebrew's global environment
HOMEBREW_ENV_CLEANUP.each { |key| ENV.delete(key) } HOMEBREW_ENV_CLEANUP.each { |key| ENV.delete(key) }
@ -157,9 +157,20 @@ module Homebrew
return return
end end
if services
require "bundle/commands/services"
exit_code = 0
Services.run_services(@dsl.entries) do
Kernel.system(*args)
exit_code = $CHILD_STATUS.exitstatus
end
exit!(exit_code)
else
exec(*args) exec(*args)
end end
end end
end end
end end
end end
end

View File

@ -114,6 +114,12 @@ module Homebrew
yield yield
ensure ensure
stop_services(entries) stop_services(entries)
conflicting_services.each do |conflict|
if conflict["running"] && conflict["registered"] && !Bundle::BrewServices.run(conflict["name"])
opoo "Failed to restart #{conflict["name"]} service"
end
end
end end
end end
end end

View File

@ -89,6 +89,8 @@ module Homebrew
"even if `$HOMEBREW_BUNDLE_NO_UPGRADE` is set. " "even if `$HOMEBREW_BUNDLE_NO_UPGRADE` is set. "
switch "--install", switch "--install",
description: "Run `install` before continuing to other operations e.g. `exec`." description: "Run `install` before continuing to other operations e.g. `exec`."
switch "--services",
description: "Temporarily start services while running the `exec` or `sh` command."
switch "-f", "--force", switch "-f", "--force",
description: "`install` runs with `--force`/`--overwrite`. " \ description: "`install` runs with `--force`/`--overwrite`. " \
"`dump` overwrites an existing `Brewfile`. " \ "`dump` overwrites an existing `Brewfile`. " \
@ -238,7 +240,7 @@ module Homebrew
["env"] ["env"]
end end
require "bundle/commands/exec" require "bundle/commands/exec"
Homebrew::Bundle::Commands::Exec.run(*named_args, global:, file:, subcommand:) Homebrew::Bundle::Commands::Exec.run(*named_args, global:, file:, subcommand:, services: args.services?)
when "list" when "list"
require "bundle/commands/list" require "bundle/commands/list"
Homebrew::Bundle::Commands::List.run( Homebrew::Bundle::Commands::List.run(

View File

@ -59,6 +59,9 @@ class Homebrew::Cmd::Bundle::Args < Homebrew::CLI::Args
sig { returns(T::Boolean) } sig { returns(T::Boolean) }
def no_vscode?; end def no_vscode?; end
sig { returns(T::Boolean) }
def services?; end
sig { returns(T::Boolean) } sig { returns(T::Boolean) }
def tap?; end def tap?; end