Skip to content

Commit

Permalink
Merge pull request #1638 from Homebrew/improve_env_output
Browse files Browse the repository at this point in the history
Improve `brew bundle env --install` output
  • Loading branch information
MikeMcQuaid authored Mar 6, 2025
2 parents 2483543 + cdac4b0 commit 32eefd7
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
2 changes: 1 addition & 1 deletion cmd/bundle.rb
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def run
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)
Bundle::Commands::Install.run(global:, file:, no_upgrade:, verbose:, force:, output: $stderr, quiet: true)
end

case subcommand
Expand Down
5 changes: 3 additions & 2 deletions lib/bundle/commands/install.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ module Commands
module Install
module_function

def run(global: false, file: nil, no_lock: false, no_upgrade: false, verbose: false, force: false, quiet: false)
def run(global: false, file: nil, no_lock: false, no_upgrade: false, verbose: false, force: false,
output: $stdout, quiet: false)
@dsl = Brewfile.read(global:, file:)
Bundle::Installer.install(
@dsl.entries,
global:, file:, no_lock:, no_upgrade:, verbose:, force:, quiet:,
global:, file:, no_lock:, no_upgrade:, verbose:, force:, output:, quiet:,
) || exit(1)
end

Expand Down
16 changes: 8 additions & 8 deletions lib/bundle/installer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module Installer
module_function

def install(entries, global: false, file: nil, no_lock: false, no_upgrade: false, verbose: false, force: false,
quiet: false)
output: $stdout, quiet: false)
success = 0
failure = 0

Expand Down Expand Up @@ -42,31 +42,31 @@ def install(entries, global: false, file: nil, no_lock: false, no_upgrade: false
next if Bundle::Skipper.skip? entry

preinstall = if cls.preinstall(*args, **options, no_upgrade:, verbose:)
puts Formatter.success("#{verb} #{name}")
output.puts Formatter.success("#{verb} #{name}")
true
else
puts "Using #{name}" unless quiet
output.puts "Using #{name}" unless quiet
false
end

if cls.install(*args, **options,
preinstall:, no_upgrade:, verbose:, force:)
success += 1
else
puts Formatter.error("#{verb} #{name} has failed!")
$stderr.puts Formatter.error("#{verb} #{name} has failed!")
failure += 1
end
end

unless failure.zero?
puts Formatter.error "Homebrew Bundle failed! " \
"#{failure} Brewfile #{Bundle::Dsl.pluralize_dependency(failure)} failed to install."
dependency = Bundle::Dsl.pluralize_dependency(failure)
$stderr.puts Formatter.error "Homebrew Bundle failed! #{failure} Brewfile #{dependency} failed to install"
return false
end

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

true
Expand Down

0 comments on commit 32eefd7

Please sign in to comment.