| 1 | """sway CLI entry point. |
| 2 | |
| 3 | ``pip install dlm-sway`` installs this module's :func:`main` as the |
| 4 | ``sway`` console script. Every subcommand is a thin wrapper around a |
| 5 | library-level function so the CLI surface mirrors what programmatic |
| 6 | callers get. |
| 7 | """ |
| 8 | |
| 9 | from __future__ import annotations |
| 10 | |
| 11 | import typer |
| 12 | |
| 13 | from dlm_sway import __version__ |
| 14 | from dlm_sway.cli import commands |
| 15 | |
| 16 | app = typer.Typer( |
| 17 | name="sway", |
| 18 | no_args_is_help=True, |
| 19 | add_completion=False, |
| 20 | help="Differential testing for fine-tuned causal language models.", |
| 21 | ) |
| 22 | |
| 23 | |
| 24 | def _version_callback(value: bool) -> None: |
| 25 | if value: |
| 26 | typer.echo(f"sway {__version__}") |
| 27 | raise typer.Exit() |
| 28 | |
| 29 | |
| 30 | @app.callback() |
| 31 | def _root( |
| 32 | version: bool = typer.Option( # noqa: B008 — typer pattern |
| 33 | False, |
| 34 | "--version", |
| 35 | callback=_version_callback, |
| 36 | is_eager=True, |
| 37 | help="Print version and exit.", |
| 38 | ), |
| 39 | ) -> None: |
| 40 | """Root callback; accepts ``--version``.""" |
| 41 | del version |
| 42 | |
| 43 | |
| 44 | app.command("run")(commands.run_cmd) |
| 45 | app.command("gate")(commands.gate_cmd) |
| 46 | app.command("check")(commands.check_cmd) |
| 47 | app.command("diff")(commands.diff_cmd) |
| 48 | app.command("autogen")(commands.autogen_cmd) |
| 49 | app.command("doctor")(commands.doctor_cmd) |
| 50 | app.command("report")(commands.report_cmd) |
| 51 | app.command("compare")(commands.compare_cmd) |
| 52 | app.command("trace")(commands.trace_cmd) |
| 53 | app.command("mine")(commands.mine_cmd) |
| 54 | app.command("list-probes")(commands.list_probes_cmd) |
| 55 | app.command("convert-adapter")(commands.convert_adapter_cmd) |
| 56 | app.command("pack")(commands.pack_cmd) |
| 57 | app.command("unpack")(commands.unpack_cmd) |
| 58 | app.command("serve")(commands.serve_cmd) |
| 59 | |
| 60 | |
| 61 | def main() -> None: |
| 62 | """Script entry point registered in :file:`pyproject.toml`.""" |
| 63 | app() |
| 64 | |
| 65 | |
| 66 | if __name__ == "__main__": |
| 67 | main() |