| 
									
										
										
										
											2025-04-19 22:22:42 +01:00
										 |  |  | # typed: strict | 
					
						
							| 
									
										
										
										
											2025-03-18 17:38:37 +00:00
										 |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-03-24 21:55:47 +08:00
										 |  |  | require "bundle/checker" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-03-18 17:38:37 +00:00
										 |  |  | module Homebrew | 
					
						
							|  |  |  |   module Bundle | 
					
						
							|  |  |  |     module Commands | 
					
						
							|  |  |  |       module Check | 
					
						
							| 
									
										
										
										
											2025-04-19 22:22:42 +01:00
										 |  |  |         sig { | 
					
						
							|  |  |  |           params(global: T::Boolean, file: T.nilable(String), no_upgrade: T::Boolean, verbose: T::Boolean, | 
					
						
							|  |  |  |                  quiet: T::Boolean).void | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2025-03-28 17:21:28 +08:00
										 |  |  |         def self.run(global: false, file: nil, no_upgrade: false, verbose: false, quiet: false) | 
					
						
							| 
									
										
										
										
											2025-03-18 17:38:37 +00:00
										 |  |  |           output_errors = verbose | 
					
						
							|  |  |  |           exit_on_first_error = !verbose | 
					
						
							|  |  |  |           check_result = Homebrew::Bundle::Checker.check( | 
					
						
							|  |  |  |             global:, file:, | 
					
						
							|  |  |  |             exit_on_first_error:, no_upgrade:, verbose: | 
					
						
							|  |  |  |           ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-03-27 15:37:31 +00:00
										 |  |  |           # Allow callers of `brew bundle check` to specify when they've already | 
					
						
							|  |  |  |           # output some formulae errors. | 
					
						
							|  |  |  |           check_missing_formulae = ENV.fetch("HOMEBREW_BUNDLE_CHECK_ALREADY_OUTPUT_FORMULAE_ERRORS", "") | 
					
						
							|  |  |  |                                       .strip | 
					
						
							|  |  |  |                                       .split | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-03-18 17:38:37 +00:00
										 |  |  |           if check_result.work_to_be_done | 
					
						
							| 
									
										
										
										
											2025-03-27 15:37:31 +00:00
										 |  |  |             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 | 
					
						
							| 
									
										
										
										
											2025-03-18 17:38:37 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |             puts "Satisfy missing dependencies with `brew bundle install`." | 
					
						
							|  |  |  |             exit 1
 | 
					
						
							|  |  |  |           end | 
					
						
							| 
									
										
										
										
											2025-03-28 17:21:28 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |           puts "The Brewfile's dependencies are satisfied." unless quiet | 
					
						
							| 
									
										
										
										
											2025-03-18 17:38:37 +00:00
										 |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end |