| 
									
										
										
										
											2020-10-10 14:16:11 +02:00
										 |  |  | # typed: false | 
					
						
							| 
									
										
										
										
											2019-04-19 15:38:03 +09:00
										 |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-04 23:14:58 +01:00
										 |  |  | require "diagnostic" | 
					
						
							| 
									
										
										
										
											2019-04-17 18:25:08 +09:00
										 |  |  | require "cli/parser" | 
					
						
							| 
									
										
										
										
											2020-07-10 10:36:59 -04:00
										 |  |  | require "cask/caskroom" | 
					
						
							| 
									
										
										
										
											2012-03-01 16:32:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-18 22:41:47 -05:00
										 |  |  | module Homebrew | 
					
						
							| 
									
										
										
										
											2020-10-20 12:03:48 +02:00
										 |  |  |   extend T::Sig | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-26 01:44:51 +02:00
										 |  |  |   module_function | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-20 12:03:48 +02:00
										 |  |  |   sig { returns(CLI::Parser) } | 
					
						
							| 
									
										
										
										
											2018-10-24 15:58:35 +05:30
										 |  |  |   def doctor_args | 
					
						
							|  |  |  |     Homebrew::CLI::Parser.new do | 
					
						
							| 
									
										
										
										
											2021-01-15 15:04:02 -05:00
										 |  |  |       description <<~EOS | 
					
						
							| 
									
										
										
										
											2019-08-20 00:04:14 -04:00
										 |  |  |         Check your system for potential problems. Will exit with a non-zero status | 
					
						
							| 
									
										
										
										
											2018-10-24 15:58:35 +05:30
										 |  |  |         if any potential problems are found. Please note that these warnings are just | 
					
						
							|  |  |  |         used to help the Homebrew maintainers with debugging if you file an issue. If | 
					
						
							|  |  |  |         everything you use Homebrew for is working fine: please don't worry or file | 
					
						
							|  |  |  |         an issue; just ignore this. | 
					
						
							|  |  |  |       EOS | 
					
						
							|  |  |  |       switch "--list-checks", | 
					
						
							| 
									
										
										
										
											2019-12-12 19:04:01 -05:00
										 |  |  |              description: "List all audit methods, which can be run individually "\ | 
					
						
							|  |  |  |                           "if provided as arguments." | 
					
						
							| 
									
										
										
										
											2018-10-24 15:58:35 +05:30
										 |  |  |       switch "-D", "--audit-debug", | 
					
						
							| 
									
										
										
										
											2019-04-30 08:44:35 +01:00
										 |  |  |              description: "Enable debugging and profiling of audit methods." | 
					
						
							| 
									
										
										
										
											2021-01-10 14:26:40 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |       named_args :diagnostic_check | 
					
						
							| 
									
										
										
										
											2018-10-24 15:58:35 +05:30
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-11-09 13:00:33 +00:00
										 |  |  |   def doctor | 
					
						
							| 
									
										
										
										
											2020-07-30 18:40:10 +02:00
										 |  |  |     args = doctor_args.parse | 
					
						
							| 
									
										
										
										
											2018-10-24 15:58:35 +05:30
										 |  |  | 
 | 
					
						
							|  |  |  |     inject_dump_stats!(Diagnostic::Checks, /^check_*/) if args.audit_debug? | 
					
						
							| 
									
										
										
										
											2016-04-18 17:39:21 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-19 17:12:32 +01:00
										 |  |  |     checks = Diagnostic::Checks.new(verbose: args.verbose?) | 
					
						
							| 
									
										
										
										
											2012-03-01 16:32:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-24 15:58:35 +05:30
										 |  |  |     if args.list_checks? | 
					
						
							| 
									
										
										
										
											2021-06-22 20:57:09 +09:00
										 |  |  |       puts checks.all | 
					
						
							| 
									
										
										
										
											2020-07-10 10:36:59 -04:00
										 |  |  |       return | 
					
						
							| 
									
										
										
										
											2012-11-13 16:49:43 -06:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-04 17:28:15 +00:00
										 |  |  |     if args.no_named? | 
					
						
							| 
									
										
										
										
											2016-01-02 01:03:54 +01:00
										 |  |  |       slow_checks = %w[
 | 
					
						
							|  |  |  |         check_for_broken_symlinks | 
					
						
							|  |  |  |         check_missing_deps | 
					
						
							|  |  |  |       ] | 
					
						
							| 
									
										
										
										
											2021-06-22 20:57:09 +09:00
										 |  |  |       methods = (checks.all - slow_checks) + slow_checks | 
					
						
							| 
									
										
										
										
											2022-03-30 17:25:00 +01:00
										 |  |  |       methods -= checks.cask_checks unless Cask::Caskroom.any_casks_installed? | 
					
						
							| 
									
										
										
										
											2012-08-14 11:21:33 -04:00
										 |  |  |     else | 
					
						
							| 
									
										
										
										
											2020-03-04 17:28:15 +00:00
										 |  |  |       methods = args.named | 
					
						
							| 
									
										
										
										
											2014-09-07 14:20:37 -05:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2012-08-14 11:21:33 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-29 11:14:46 -07:00
										 |  |  |     first_warning = true | 
					
						
							| 
									
										
										
										
											2012-08-14 11:21:33 -04:00
										 |  |  |     methods.each do |method| | 
					
						
							| 
									
										
										
										
											2019-11-29 14:54:41 -05:00
										 |  |  |       $stderr.puts Formatter.headline("Checking #{method}", color: :magenta) if args.debug? | 
					
						
							| 
									
										
										
										
											2016-01-05 15:53:57 +01:00
										 |  |  |       unless checks.respond_to?(method) | 
					
						
							| 
									
										
										
										
											2020-07-29 19:41:39 -04:00
										 |  |  |         ofail "No check available by the name: #{method}" | 
					
						
							| 
									
										
										
										
											2014-11-26 17:54:53 -08:00
										 |  |  |         next | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2016-01-05 15:53:57 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |       out = checks.send(method) | 
					
						
							| 
									
										
										
										
											2020-12-01 17:04:59 +00:00
										 |  |  |       next if out.blank? | 
					
						
							| 
									
										
										
										
											2018-09-17 02:45:00 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-10 10:24:56 +01:00
										 |  |  |       if first_warning | 
					
						
							| 
									
										
										
										
											2017-10-15 02:28:32 +02:00
										 |  |  |         $stderr.puts <<~EOS | 
					
						
							| 
									
										
										
										
											2016-08-30 21:38:13 +02:00
										 |  |  |           #{Tty.bold}Please note that these warnings are just used to help the Homebrew maintainers | 
					
						
							|  |  |  |           with debugging if you file an issue. If everything you use Homebrew for is | 
					
						
							| 
									
										
										
										
											2017-12-11 15:27:18 +00:00
										 |  |  |           working fine: please don't worry or file an issue; just ignore this. Thanks!#{Tty.reset} | 
					
						
							| 
									
										
										
										
											2016-09-10 10:24:56 +01:00
										 |  |  |         EOS | 
					
						
							| 
									
										
										
										
											2012-03-01 16:32:02 +00:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2016-09-10 10:24:56 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |       $stderr.puts | 
					
						
							|  |  |  |       opoo out | 
					
						
							|  |  |  |       Homebrew.failed = true | 
					
						
							|  |  |  |       first_warning = false | 
					
						
							| 
									
										
										
										
											2011-05-21 03:40:48 +02:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2010-11-09 13:00:33 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-12 19:30:56 -05:00
										 |  |  |     puts "Your system is ready to brew." unless Homebrew.failed? | 
					
						
							| 
									
										
										
										
											2010-03-31 14:55:41 -07:00
										 |  |  |   end | 
					
						
							|  |  |  | end |