Skip to content
This repository was archived by the owner on Apr 22, 2025. It is now read-only.
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
24 changes: 15 additions & 9 deletions cmd/bundle.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ class BundleCmd < AbstractCommand
switch "--upgrade",
description: "`install` runs `brew upgrade` on outdated dependencies, " \
"even if `$HOMEBREW_BUNDLE_NO_UPGRADE` is set. "
switch "--install",
description: "Run `install` before continuing to other operations e.g. `exec`."
switch "-f", "--force",
description: "`install` runs with `--force`/`--overwrite`. " \
"`dump` overwrites an existing `Brewfile`. " \
Expand All @@ -93,9 +95,6 @@ class BundleCmd < AbstractCommand
description: "`install` performs cleanup operation, same as running `cleanup --force`. " \
"This is enabled by default if `$HOMEBREW_BUNDLE_INSTALL_CLEANUP` is set and " \
"`--global` is passed."
switch "--no-lock",
description: "no-op since `Brewfile.lock.json` was removed.",
hidden: true
switch "--all",
description: "`list` all dependencies."
switch "--formula", "--brews",
Expand Down Expand Up @@ -126,6 +125,7 @@ class BundleCmd < AbstractCommand

conflicts "--all", "--no-vscode"
conflicts "--vscode", "--no-vscode"
conflicts "--install", "--upgrade"

named_args %w[install dump cleanup check exec list sh env edit]
end
Expand Down Expand Up @@ -154,13 +154,17 @@ def run

no_type_args = !args.brews? && !args.casks? && !args.taps? && !args.mas? && !args.whalebrew? && !args.vscode?

if args.install?
if [nil, "install", "upgrade"].include?(subcommand)
raise UsageError, "`--install` cannot be used with `install`, `upgrade` or no subcommand."
end

Bundle::Commands::Install.run(global:, file:, no_upgrade:, verbose:, force:, quiet: true)
end

case subcommand
when nil, "install", "upgrade"
Bundle::Commands::Install.run(
global:, file:, no_upgrade:, verbose:, force:,
no_lock: args.no_lock?,
quiet: args.quiet?
)
Bundle::Commands::Install.run(global:, file:, no_upgrade:, verbose:, force:, quiet: args.quiet?)

cleanup = if ENV.fetch("HOMEBREW_BUNDLE_INSTALL_CLEANUP", nil)
args.global?
Expand Down Expand Up @@ -202,6 +206,7 @@ def run
when "check"
Bundle::Commands::Check.run(global:, file:, no_upgrade:, verbose:)
when "exec", "sh", "env"
env = false
named_args = case subcommand
when "exec"
_subcommand, *named_args = args.named
Expand All @@ -220,9 +225,10 @@ def run
ENV["HOMEBREW_FORCE_API_AUTO_UPDATE"] = nil
[subshell]
when "env"
env = true
["env"]
end
Bundle::Commands::Exec.run(*named_args, global:, file:)
Bundle::Commands::Exec.run(*named_args, global:, file:, env:)
when "list"
Bundle::Commands::List.run(
global:,
Expand Down
4 changes: 2 additions & 2 deletions cmd/bundle.rbi
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ class Homebrew::Cmd::BundleCmd::Args < Homebrew::CLI::Args
def global?; end

sig { returns(T::Boolean) }
def mas?; end
def install?; end

sig { returns(T::Boolean) }
def no_lock?; end
def mas?; end

sig { returns(T::Boolean) }
def no_restart?; end
Expand Down
9 changes: 8 additions & 1 deletion lib/bundle/commands/exec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module Commands
module Exec
module_function

def run(*args, global: false, file: nil)
def run(*args, global: false, file: nil, env: false)
# Setup Homebrew's ENV extensions
ENV.activate_extensions!
raise UsageError, "No command to execute was specified!" if args.blank?
Expand Down Expand Up @@ -88,6 +88,13 @@ def run(*args, global: false, file: nil)
end
end

if env
ENV.each do |key, value|
puts "export #{key}=\"#{value}\""
end
return
end

exec(*args)
end
end
Expand Down
7 changes: 5 additions & 2 deletions lib/bundle/installer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,11 @@ def install(entries, global: false, file: nil, no_lock: false, no_upgrade: false
return false
end

puts Formatter.success "Homebrew Bundle complete! " \
"#{success} Brewfile #{Bundle::Dsl.pluralize_dependency(success)} now installed."
unless quiet
puts Formatter.success "Homebrew Bundle complete! " \
"#{success} Brewfile #{Bundle::Dsl.pluralize_dependency(success)} now installed."
end

true
end
end
Expand Down
9 changes: 9 additions & 0 deletions spec/bundle/commands/exec_command_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@
end
end

context "with env command" do
it "outputs the environment variables" do
ENV["HOMEBREW_PREFIX"] = "/opt/homebrew"

expect { described_class.run("env", env: true) }.to \
output(/HOMEBREW_PREFIX="#{ENV.fetch("HOMEBREW_PREFIX")}"/).to_stdout
end
end

it "raises if called with a command that's not on the PATH" do
allow(described_class).to receive_messages(exec: nil, which: nil)
expect { described_class.run("bundle", "install") }.to raise_error(RuntimeError)
Expand Down