diff --git a/src/modelfuzz/cli.py b/src/modelfuzz/cli.py index badb7ed..14506e6 100644 --- a/src/modelfuzz/cli.py +++ b/src/modelfuzz/cli.py @@ -273,8 +273,21 @@ def _truncate(text: str, limit: int = 140) -> str: return collapsed[: limit - 1] + "…" +def _version_callback(value: bool) -> None: + if value: + typer.echo(__version__) + raise typer.Exit() + + @app.callback() -def cli() -> None: +def cli( + version: bool = typer.Option( + None, "--version", "-V", + callback=_version_callback, + is_eager=True, + help="Show the installed version and exit.", + ), +) -> None: """Runtime guardrails for AI agents.""" diff --git a/tests/test_scan.py b/tests/test_scan.py index c4dc727..c382d3b 100644 --- a/tests/test_scan.py +++ b/tests/test_scan.py @@ -89,6 +89,12 @@ def _run(monkeypatch, client, args=None): full_args += args return runner.invoke(cli.app, full_args) +def test_version_flag_prints_version(): + from modelfuzz import __version__ + result = runner.invoke(cli.app, ["--version"]) + assert result.exit_code == 0 + assert __version__ in result.output + def test_all_seeds_vulnerable_on_first_probe(monkeypatch): client = StubClient(probe_result=_tool_call_response())