def doctor( # noqa: PLR0913
ctx: typer.Context,
output_format: Annotated[
DoctorFormat,
typer.Option(
"--format",
help="Output format: 'text' (default), 'markdown' to paste into an issue, or 'json'.",
),
] = DoctorFormat.text,
verbose: Annotated[
bool,
typer.Option("--verbose/--quiet", help="Include the explanation and remedy for each finding."),
] = True,
strict: Annotated[
bool,
typer.Option(help="Exit non-zero for warnings as well as errors."),
] = False,
environment: Annotated[
bool | None,
typer.Option(
"--environment/--no-environment",
help="Include a description of this deployment. On by default for the markdown and json formats.",
),
] = None,
list_checks: Annotated[
bool,
typer.Option("--list", help="List the available checks and where they came from, then exit."),
] = False,
) -> None:
"""
Check this deployment for data and configuration problems.
Use `--format markdown` to produce a report,
including a description of this deployment that can be pasted into a bug report.
Exits non-zero if any error is found, or any warning when --strict is used.
"""
console = ctx.obj.console
if list_checks:
_list_checks(console)
return
# The environment is the point of the machine-readable formats, and noise in the default one.
if environment is None:
environment = output_format != DoctorFormat.text
context = DoctorContext(config=ctx.obj.config, database=ctx.obj.database)
report = diagnose(context, environment=environment)
if output_format == DoctorFormat.json:
print(_render_json(report))
elif output_format == DoctorFormat.markdown:
print(_render_markdown(report))
else:
if report.findings:
# Stated before the findings so the size of the problem does not need scrolling to.
console.print(f"[bold]{_summary_line(report.findings, report.check_count)}[/bold]")
_print_findings(console, report.findings, verbose)
else:
console.print(f"[green]No problems found[/green] ({pluralise(report.check_count, 'check')})")
if report.environment is not None:
_print_environment(console, report.environment)
if report.worst_severity == Severity.ERROR or (strict and report.worst_severity == Severity.WARNING):
raise typer.Exit(1)