Merge pull request #19637 from Homebrew/bundle-exec-with-optional-check
bundle/commands/exec: check that `Brewfile` is installed with `--check`
This commit is contained in:
commit
acf455bac1
@ -7,7 +7,7 @@ module Homebrew
|
|||||||
module Bundle
|
module Bundle
|
||||||
module Commands
|
module Commands
|
||||||
module Check
|
module Check
|
||||||
def self.run(global: false, file: nil, no_upgrade: false, verbose: false)
|
def self.run(global: false, file: nil, no_upgrade: false, verbose: false, quiet: false)
|
||||||
output_errors = verbose
|
output_errors = verbose
|
||||||
exit_on_first_error = !verbose
|
exit_on_first_error = !verbose
|
||||||
check_result = Homebrew::Bundle::Checker.check(
|
check_result = Homebrew::Bundle::Checker.check(
|
||||||
@ -37,9 +37,9 @@ module Homebrew
|
|||||||
|
|
||||||
puts "Satisfy missing dependencies with `brew bundle install`."
|
puts "Satisfy missing dependencies with `brew bundle install`."
|
||||||
exit 1
|
exit 1
|
||||||
else
|
|
||||||
puts "The Brewfile's dependencies are satisfied."
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
puts "The Brewfile's dependencies are satisfied." unless quiet
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -13,7 +13,12 @@ module Homebrew
|
|||||||
module Exec
|
module Exec
|
||||||
PATH_LIKE_ENV_REGEX = /.+#{File::PATH_SEPARATOR}/
|
PATH_LIKE_ENV_REGEX = /.+#{File::PATH_SEPARATOR}/
|
||||||
|
|
||||||
def self.run(*args, global: false, file: nil, subcommand: "", services: false)
|
def self.run(*args, global: false, file: nil, subcommand: "", services: false, check: false)
|
||||||
|
if check
|
||||||
|
require "bundle/commands/check"
|
||||||
|
Homebrew::Bundle::Commands::Check.run(global:, file:, quiet: true)
|
||||||
|
end
|
||||||
|
|
||||||
# Store the old environment so we can check if things were already set
|
# Store the old environment so we can check if things were already set
|
||||||
# before we start mutating it.
|
# before we start mutating it.
|
||||||
old_env = ENV.to_h
|
old_env = ENV.to_h
|
||||||
|
@ -51,15 +51,15 @@ module Homebrew
|
|||||||
`brew bundle remove` <name> [...]:
|
`brew bundle remove` <name> [...]:
|
||||||
Remove entries that match `name` from your `Brewfile`. Use `--formula`, `--cask`, `--tap`, `--mas`, `--whalebrew` or `--vscode` to remove only entries of the corresponding type. Passing `--formula` also removes matches against formula aliases and old formula names.
|
Remove entries that match `name` from your `Brewfile`. Use `--formula`, `--cask`, `--tap`, `--mas`, `--whalebrew` or `--vscode` to remove only entries of the corresponding type. Passing `--formula` also removes matches against formula aliases and old formula names.
|
||||||
|
|
||||||
`brew bundle exec` <command>:
|
`brew bundle exec` [--check] <command>:
|
||||||
Run an external command in an isolated build environment based on the `Brewfile` dependencies.
|
Run an external command in an isolated build environment based on the `Brewfile` dependencies.
|
||||||
|
|
||||||
This sanitized build environment ignores unrequested dependencies, which makes sure that things you didn't specify in your `Brewfile` won't get picked up by commands like `bundle install`, `npm install`, etc. It will also add compiler flags which will help with finding keg-only dependencies like `openssl`, `icu4c`, etc.
|
This sanitized build environment ignores unrequested dependencies, which makes sure that things you didn't specify in your `Brewfile` won't get picked up by commands like `bundle install`, `npm install`, etc. It will also add compiler flags which will help with finding keg-only dependencies like `openssl`, `icu4c`, etc.
|
||||||
|
|
||||||
`brew bundle sh`:
|
`brew bundle sh` [--check]:
|
||||||
Run your shell in a `brew bundle exec` environment.
|
Run your shell in a `brew bundle exec` environment.
|
||||||
|
|
||||||
`brew bundle env`:
|
`brew bundle env` [--check]:
|
||||||
Print the environment variables that would be set in a `brew bundle exec` environment.
|
Print the environment variables that would be set in a `brew bundle exec` environment.
|
||||||
EOS
|
EOS
|
||||||
flag "--file=",
|
flag "--file=",
|
||||||
@ -126,6 +126,9 @@ module Homebrew
|
|||||||
description: "`dump` does not add `restart_service` to formula lines."
|
description: "`dump` does not add `restart_service` to formula lines."
|
||||||
switch "--zap",
|
switch "--zap",
|
||||||
description: "`cleanup` casks using the `zap` command instead of `uninstall`."
|
description: "`cleanup` casks using the `zap` command instead of `uninstall`."
|
||||||
|
switch "--check",
|
||||||
|
description: "Check that all dependencies in the Brewfile are installed before " \
|
||||||
|
"running `exec`, `sh`, or `env`."
|
||||||
|
|
||||||
conflicts "--all", "--no-vscode"
|
conflicts "--all", "--no-vscode"
|
||||||
conflicts "--vscode", "--no-vscode"
|
conflicts "--vscode", "--no-vscode"
|
||||||
@ -134,6 +137,8 @@ module Homebrew
|
|||||||
named_args %w[install dump cleanup check exec list sh env edit]
|
named_args %w[install dump cleanup check exec list sh env edit]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
BUNDLE_EXEC_COMMANDS = %w[exec sh env].freeze
|
||||||
|
|
||||||
sig { override.void }
|
sig { override.void }
|
||||||
def run
|
def run
|
||||||
# Keep this inside `run` to keep --help fast.
|
# Keep this inside `run` to keep --help fast.
|
||||||
@ -144,6 +149,10 @@ module Homebrew
|
|||||||
raise UsageError, "This command does not take more than 1 subcommand argument."
|
raise UsageError, "This command does not take more than 1 subcommand argument."
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if args.check? && BUNDLE_EXEC_COMMANDS.exclude?(subcommand)
|
||||||
|
raise UsageError, "`--check` can be used only with #{BUNDLE_EXEC_COMMANDS.join(", ")}."
|
||||||
|
end
|
||||||
|
|
||||||
global = args.global?
|
global = args.global?
|
||||||
file = args.file
|
file = args.file
|
||||||
args.zap?
|
args.zap?
|
||||||
@ -219,28 +228,6 @@ module Homebrew
|
|||||||
when "check"
|
when "check"
|
||||||
require "bundle/commands/check"
|
require "bundle/commands/check"
|
||||||
Homebrew::Bundle::Commands::Check.run(global:, file:, no_upgrade:, verbose:)
|
Homebrew::Bundle::Commands::Check.run(global:, file:, no_upgrade:, verbose:)
|
||||||
when "exec", "sh", "env"
|
|
||||||
named_args = case subcommand
|
|
||||||
when "exec"
|
|
||||||
_subcommand, *named_args = args.named
|
|
||||||
named_args
|
|
||||||
when "sh"
|
|
||||||
preferred_path = Utils::Shell.preferred_path(default: "/bin/bash")
|
|
||||||
notice = unless Homebrew::EnvConfig.no_env_hints?
|
|
||||||
<<~EOS
|
|
||||||
Your shell has been configured to use a build environment from your `Brewfile`.
|
|
||||||
This should help you build stuff.
|
|
||||||
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).
|
|
||||||
When done, type `exit`.
|
|
||||||
EOS
|
|
||||||
end
|
|
||||||
ENV["HOMEBREW_FORCE_API_AUTO_UPDATE"] = nil
|
|
||||||
[Utils::Shell.shell_with_prompt("brew bundle", preferred_path:, notice:)]
|
|
||||||
when "env"
|
|
||||||
["env"]
|
|
||||||
end
|
|
||||||
require "bundle/commands/exec"
|
|
||||||
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(
|
||||||
@ -281,6 +268,28 @@ module Homebrew
|
|||||||
require "bundle/commands/remove"
|
require "bundle/commands/remove"
|
||||||
Homebrew::Bundle::Commands::Remove.run(*named_args, type: selected_types.first, global:, file:)
|
Homebrew::Bundle::Commands::Remove.run(*named_args, type: selected_types.first, global:, file:)
|
||||||
end
|
end
|
||||||
|
when *BUNDLE_EXEC_COMMANDS
|
||||||
|
named_args = case subcommand
|
||||||
|
when "exec"
|
||||||
|
_subcommand, *named_args = args.named
|
||||||
|
named_args
|
||||||
|
when "sh"
|
||||||
|
preferred_path = Utils::Shell.preferred_path(default: "/bin/bash")
|
||||||
|
notice = unless Homebrew::EnvConfig.no_env_hints?
|
||||||
|
<<~EOS
|
||||||
|
Your shell has been configured to use a build environment from your `Brewfile`.
|
||||||
|
This should help you build stuff.
|
||||||
|
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).
|
||||||
|
When done, type `exit`.
|
||||||
|
EOS
|
||||||
|
end
|
||||||
|
ENV["HOMEBREW_FORCE_API_AUTO_UPDATE"] = nil
|
||||||
|
[Utils::Shell.shell_with_prompt("brew bundle", preferred_path:, notice:)]
|
||||||
|
when "env"
|
||||||
|
["env"]
|
||||||
|
end
|
||||||
|
require "bundle/commands/exec"
|
||||||
|
Homebrew::Bundle::Commands::Exec.run(*named_args, global:, file:, subcommand:, services: args.services?)
|
||||||
else
|
else
|
||||||
raise UsageError, "unknown subcommand: #{subcommand}"
|
raise UsageError, "unknown subcommand: #{subcommand}"
|
||||||
end
|
end
|
||||||
|
@ -23,6 +23,9 @@ class Homebrew::Cmd::Bundle::Args < Homebrew::CLI::Args
|
|||||||
sig { returns(T::Boolean) }
|
sig { returns(T::Boolean) }
|
||||||
def casks?; end
|
def casks?; end
|
||||||
|
|
||||||
|
sig { returns(T::Boolean) }
|
||||||
|
def check?; end
|
||||||
|
|
||||||
sig { returns(T::Boolean) }
|
sig { returns(T::Boolean) }
|
||||||
def cleanup?; end
|
def cleanup?; end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user