Allow callers of brew bundle check to filter errors.

If callers of `brew bundle check` have already output some formulae
errors, they can set the
`HOMEBREW_BUNDLE_CHECK_ALREADY_OUTPUT_FORMULAE_ERRORS` environment
variable to the names of the formulae that have already been output.
This commit is contained in:
Mike McQuaid 2025-03-27 15:37:31 +00:00
parent 5ec5063dc7
commit d3a64157e1
No known key found for this signature in database

View File

@ -7,9 +7,6 @@ module Homebrew
module Bundle module Bundle
module Commands module Commands
module Check module Check
ARROW = ""
FAILURE_MESSAGE = "brew bundle can't satisfy your Brewfile's dependencies."
def self.run(global: false, file: nil, no_upgrade: false, verbose: false) def self.run(global: false, file: nil, no_upgrade: false, verbose: false)
output_errors = verbose output_errors = verbose
exit_on_first_error = !verbose exit_on_first_error = !verbose
@ -18,10 +15,26 @@ module Homebrew
exit_on_first_error:, no_upgrade:, verbose: exit_on_first_error:, no_upgrade:, verbose:
) )
if check_result.work_to_be_done # Allow callers of `brew bundle check` to specify when they've already
puts FAILURE_MESSAGE # output some formulae errors.
check_missing_formulae = ENV.fetch("HOMEBREW_BUNDLE_CHECK_ALREADY_OUTPUT_FORMULAE_ERRORS", "")
.strip
.split
if check_result.work_to_be_done
puts "brew bundle can't satisfy your Brewfile's dependencies." if check_missing_formulae.blank?
if output_errors
check_result.errors.each do |error|
if (match = error.match(/^Formula (.+) needs to be installed/)) &&
check_missing_formulae.include?(match[1])
next
end
puts "#{error}"
end
end
check_result.errors.each { |package| puts "#{ARROW} #{package}" } if output_errors
puts "Satisfy missing dependencies with `brew bundle install`." puts "Satisfy missing dependencies with `brew bundle install`."
exit 1 exit 1
else else