diff --git a/Library/Homebrew/cmd/doctor.rb b/Library/Homebrew/cmd/doctor.rb index a273921d8e34a..61257417e7c83 100644 --- a/Library/Homebrew/cmd/doctor.rb +++ b/Library/Homebrew/cmd/doctor.rb @@ -23,6 +23,11 @@ class Doctor < AbstractCommand switch "-D", "--audit-debug", description: "Enable debugging and profiling of audit methods." + switch "--ignore-warnings", + description: "Only exit with a non-zero status if errors are " \ + "encountered. Warnings are still displayed but will " \ + "not cause the command to fail." + named_args :diagnostic_check end @@ -48,7 +53,7 @@ def run methods = args.named end - first_warning = T.let(true, T::Boolean) + seen_warning = T.let(false, T::Boolean) methods.each do |method| $stderr.puts Formatter.headline("Checking #{method}", color: :magenta) if args.debug? unless checks.respond_to?(method) @@ -59,7 +64,7 @@ def run out = checks.send(method) next if out.blank? - if first_warning + unless seen_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 @@ -69,11 +74,11 @@ def run $stderr.puts opoo out - Homebrew.failed = true - first_warning = false + Homebrew.failed = true unless args.ignore_warnings? + seen_warning = true end - puts "Your system is ready to brew." if !Homebrew.failed? && !args.quiet? + puts "Your system is ready to brew." if !Homebrew.failed? && !seen_warning && !args.quiet? end end end diff --git a/Library/Homebrew/sorbet/rbi/dsl/homebrew/cmd/doctor.rbi b/Library/Homebrew/sorbet/rbi/dsl/homebrew/cmd/doctor.rbi index 76369fc38b7b2..80fe5c702f558 100644 --- a/Library/Homebrew/sorbet/rbi/dsl/homebrew/cmd/doctor.rbi +++ b/Library/Homebrew/sorbet/rbi/dsl/homebrew/cmd/doctor.rbi @@ -17,6 +17,9 @@ class Homebrew::Cmd::Doctor::Args < Homebrew::CLI::Args sig { returns(T::Boolean) } def audit_debug?; end + sig { returns(T::Boolean) } + def ignore_warnings?; end + sig { returns(T::Boolean) } def list_checks?; end end