From ab56cff6bea49a3c0a45038ca2e2c487b02e47a3 Mon Sep 17 00:00:00 2001 From: Rebecca Turner Date: Thu, 25 Jul 2024 11:50:18 -0700 Subject: [PATCH] cmd/doctor: Add --ignore-warnings When `brew doctor` is run, `brew` exits with a non-zero status if any warnings or errors are encountered. However, this groups warnings and errors together, but (as the output notes) warnings can be innocuous: > 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! The `--ignore-warnings` switch makes it possible for automated tools interacting with Homebrew to distinguish between warnings and hard errors. ``` $ brew doctor --ignore-warnings 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! Warning: Some installed casks are deprecated or disabled. You should find replacements for the following casks: graphql-playground $ echo "$?" 0 ``` Hard errors will still cause a non-zero exit status: ``` $ brew doctor --ignore-warnings 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! Warning: gettext files detected at a system prefix. These files can cause compilation and link failures, especially if they are compiled with improper architectures. Consider removing these files: /opt/homebrew/lib/libgettextlib.dylib /opt/homebrew/lib/libintl.dylib /opt/homebrew/include/libintl.h Error: unknown or unsupported macOS version: :dunno $ echo "$?" 1 ``` --- Library/Homebrew/cmd/doctor.rb | 15 ++++++++++----- .../sorbet/rbi/dsl/homebrew/cmd/doctor.rbi | 3 +++ 2 files changed, 13 insertions(+), 5 deletions(-) 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