"""Transport for the `dev` domain — args in, delegate, format out.""" from __future__ import annotations import typer from tooling.core import cli, console from tooling.core.command import command from tooling.core.errors import ReachError from tooling.domains.dev import service app = cli.domain("dev", "Developer environment and self-diagnosis.") @app.callback() def _domain() -> None: """Keeps `dev` a group (Typer collapses a single-command app).""" @app.command("selftest") @command def selftest( seconds: float = typer.Option(2.0, "--seconds", "-s", help="Roughly how long to run."), fail: bool = typer.Option(False, "--fail", help="Exit non-zero at the end."), exit_code: int = typer.Option(1, "--exit-code", help="Which code to fail with."), ) -> None: """Emit progress for a while, then succeed or fail on purpose. A real diagnostic — "does streaming work end to end on this machine, can I tail it, does a failure survive a detached run?" — and the only command in reach slow enough to answer those by observation rather than argument. Every other verb finishes in milliseconds. """ for step, total in service.slow_work(seconds): console.event( f"step {step} of {total}", phase="selftest", progress=step / total, ) if fail: raise ReachError( f"selftest failed on purpose after {seconds:g}s", fix="this command failed because --fail was passed; drop it to succeed", exit_code=exit_code, ) console.verdict(f"selftest: OK — {seconds:g}s of progress, no failures")