Port Homebrew::Cmd::Doctor
This commit is contained in:
		
							parent
							
								
									67fd065e1d
								
							
						
					
					
						commit
						f83ba58f8d
					
				@ -1,80 +1,80 @@
 | 
				
			|||||||
# typed: true
 | 
					# typed: strict
 | 
				
			||||||
# frozen_string_literal: true
 | 
					# frozen_string_literal: true
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					require "abstract_command"
 | 
				
			||||||
require "diagnostic"
 | 
					require "diagnostic"
 | 
				
			||||||
require "cli/parser"
 | 
					 | 
				
			||||||
require "cask/caskroom"
 | 
					require "cask/caskroom"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
module Homebrew
 | 
					module Homebrew
 | 
				
			||||||
  sig { returns(CLI::Parser) }
 | 
					  module Cmd
 | 
				
			||||||
  def self.doctor_args
 | 
					    class Doctor < AbstractCommand
 | 
				
			||||||
    Homebrew::CLI::Parser.new do
 | 
					      cmd_args do
 | 
				
			||||||
      description <<~EOS
 | 
					        description <<~EOS
 | 
				
			||||||
        Check your system for potential problems. Will exit with a non-zero status
 | 
					          Check your system for potential problems. Will exit with a non-zero status
 | 
				
			||||||
        if any potential problems are found.
 | 
					          if any potential problems are found.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Please note that these warnings are just used to help the Homebrew maintainers
 | 
					          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
 | 
					          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.
 | 
					          is working fine: please don't worry or file an issue; just ignore this.
 | 
				
			||||||
      EOS
 | 
					 | 
				
			||||||
      switch "--list-checks",
 | 
					 | 
				
			||||||
             description: "List all audit methods, which can be run individually " \
 | 
					 | 
				
			||||||
                          "if provided as arguments."
 | 
					 | 
				
			||||||
      switch "-D", "--audit-debug",
 | 
					 | 
				
			||||||
             description: "Enable debugging and profiling of audit methods."
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      named_args :diagnostic_check
 | 
					 | 
				
			||||||
    end
 | 
					 | 
				
			||||||
  end
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  def self.doctor
 | 
					 | 
				
			||||||
    args = doctor_args.parse
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    inject_dump_stats!(Diagnostic::Checks, /^check_*/) if args.audit_debug?
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    checks = Diagnostic::Checks.new(verbose: args.verbose?)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    if args.list_checks?
 | 
					 | 
				
			||||||
      puts checks.all
 | 
					 | 
				
			||||||
      return
 | 
					 | 
				
			||||||
    end
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    if args.no_named?
 | 
					 | 
				
			||||||
      slow_checks = %w[
 | 
					 | 
				
			||||||
        check_for_broken_symlinks
 | 
					 | 
				
			||||||
        check_missing_deps
 | 
					 | 
				
			||||||
      ]
 | 
					 | 
				
			||||||
      methods = (checks.all - slow_checks) + slow_checks
 | 
					 | 
				
			||||||
      methods -= checks.cask_checks unless Cask::Caskroom.any_casks_installed?
 | 
					 | 
				
			||||||
    else
 | 
					 | 
				
			||||||
      methods = args.named
 | 
					 | 
				
			||||||
    end
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    first_warning = T.let(true, T::Boolean)
 | 
					 | 
				
			||||||
    methods.each do |method|
 | 
					 | 
				
			||||||
      $stderr.puts Formatter.headline("Checking #{method}", color: :magenta) if args.debug?
 | 
					 | 
				
			||||||
      unless checks.respond_to?(method)
 | 
					 | 
				
			||||||
        ofail "No check available by the name: #{method}"
 | 
					 | 
				
			||||||
        next
 | 
					 | 
				
			||||||
      end
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      out = checks.send(method)
 | 
					 | 
				
			||||||
      next if out.blank?
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      if first_warning
 | 
					 | 
				
			||||||
        $stderr.puts <<~EOS
 | 
					 | 
				
			||||||
          #{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
 | 
					 | 
				
			||||||
          working fine: please don't worry or file an issue; just ignore this. Thanks!#{Tty.reset}
 | 
					 | 
				
			||||||
        EOS
 | 
					        EOS
 | 
				
			||||||
 | 
					        switch "--list-checks",
 | 
				
			||||||
 | 
					               description: "List all audit methods, which can be run individually " \
 | 
				
			||||||
 | 
					                            "if provided as arguments."
 | 
				
			||||||
 | 
					        switch "-D", "--audit-debug",
 | 
				
			||||||
 | 
					               description: "Enable debugging and profiling of audit methods."
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        named_args :diagnostic_check
 | 
				
			||||||
      end
 | 
					      end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      $stderr.puts
 | 
					      sig { override.void }
 | 
				
			||||||
      opoo out
 | 
					      def run
 | 
				
			||||||
      Homebrew.failed = true
 | 
					        Homebrew.inject_dump_stats!(Diagnostic::Checks, /^check_*/) if args.audit_debug?
 | 
				
			||||||
      first_warning = false
 | 
					 | 
				
			||||||
    end
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    puts "Your system is ready to brew." if !Homebrew.failed? && !args.quiet?
 | 
					        checks = Diagnostic::Checks.new(verbose: args.verbose?)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if args.list_checks?
 | 
				
			||||||
 | 
					          puts checks.all
 | 
				
			||||||
 | 
					          return
 | 
				
			||||||
 | 
					        end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if args.no_named?
 | 
				
			||||||
 | 
					          slow_checks = %w[
 | 
				
			||||||
 | 
					            check_for_broken_symlinks
 | 
				
			||||||
 | 
					            check_missing_deps
 | 
				
			||||||
 | 
					          ]
 | 
				
			||||||
 | 
					          methods = (checks.all - slow_checks) + slow_checks
 | 
				
			||||||
 | 
					          methods -= checks.cask_checks unless Cask::Caskroom.any_casks_installed?
 | 
				
			||||||
 | 
					        else
 | 
				
			||||||
 | 
					          methods = args.named
 | 
				
			||||||
 | 
					        end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        first_warning = T.let(true, T::Boolean)
 | 
				
			||||||
 | 
					        methods.each do |method|
 | 
				
			||||||
 | 
					          $stderr.puts Formatter.headline("Checking #{method}", color: :magenta) if args.debug?
 | 
				
			||||||
 | 
					          unless checks.respond_to?(method)
 | 
				
			||||||
 | 
					            ofail "No check available by the name: #{method}"
 | 
				
			||||||
 | 
					            next
 | 
				
			||||||
 | 
					          end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					          out = checks.send(method)
 | 
				
			||||||
 | 
					          next if out.blank?
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					          if first_warning
 | 
				
			||||||
 | 
					            $stderr.puts <<~EOS
 | 
				
			||||||
 | 
					              #{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
 | 
				
			||||||
 | 
					              working fine: please don't worry or file an issue; just ignore this. Thanks!#{Tty.reset}
 | 
				
			||||||
 | 
					            EOS
 | 
				
			||||||
 | 
					          end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					          $stderr.puts
 | 
				
			||||||
 | 
					          opoo out
 | 
				
			||||||
 | 
					          Homebrew.failed = true
 | 
				
			||||||
 | 
					          first_warning = false
 | 
				
			||||||
 | 
					        end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        puts "Your system is ready to brew." if !Homebrew.failed? && !args.quiet?
 | 
				
			||||||
 | 
					      end
 | 
				
			||||||
 | 
					    end
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 | 
				
			|||||||
@ -1,8 +1,9 @@
 | 
				
			|||||||
# frozen_string_literal: true
 | 
					# frozen_string_literal: true
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					require "cmd/doctor"
 | 
				
			||||||
require "cmd/shared_examples/args_parse"
 | 
					require "cmd/shared_examples/args_parse"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
RSpec.describe "brew doctor" do
 | 
					RSpec.describe Homebrew::Cmd::Doctor do
 | 
				
			||||||
  it_behaves_like "parseable arguments"
 | 
					  it_behaves_like "parseable arguments"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  specify "check_integration_test", :integration_test do
 | 
					  specify "check_integration_test", :integration_test do
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user