Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 27 additions & 3 deletions Library/Homebrew/cmd/doctor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
require "abstract_command"
require "diagnostic"
require "cask/caskroom"
require "json"

module Homebrew
module Cmd
Expand All @@ -20,6 +21,8 @@ class Doctor < AbstractCommand
switch "--list-checks",
description: "List all audit methods, which can be run individually " \
"if provided as arguments."
switch "--json",
description: "Print a JSON representation."
switch "-D", "--audit-debug",
description: "Enable debugging and profiling of audit methods."

Expand Down Expand Up @@ -48,6 +51,7 @@ def run
methods = args.named
end

findings = []
first_warning = T.let(true, T::Boolean)
methods.each do |method|
$stderr.puts Formatter.headline("Checking #{method}", color: :magenta) if args.debug?
Expand All @@ -56,8 +60,21 @@ def run
next
end

out = checks.send(method)
next if out.blank?
finding = checks.send(method)

return_findings = if finding.is_a?(Array)
T.let(finding.compact, T::Array[Diagnostic::Finding])
else
T.let([finding].compact, T::Array[Diagnostic::Finding])
end

next if return_findings.empty?

if args.json?
Homebrew.failed = true
findings.concat(return_findings.compact.map(&:to_h))
next
end

if first_warning && !args.quiet?
$stderr.puts <<~EOS
Expand All @@ -68,11 +85,18 @@ def run
end

$stderr.puts
opoo out
opoo return_findings.each(&:to_s).join("\n")
Homebrew.failed = true
first_warning = false
end

if args.json?
tier = findings.max_by { |f| f[:tier] }&.fetch(:tier, 1)
puts JSON.pretty_generate({ tier: tier, findings: findings }).gsub(/\[\n\n\s*\]/, "[]")

return
end

puts "Your system is ready to brew." if !Homebrew.failed? && !args.quiet?
end
end
Expand Down
Loading
Loading