From b1de9ced2ea5f96d2cebd3c83a29f6cff53d5612 Mon Sep 17 00:00:00 2001 From: Muhamed Fazal PS Date: Wed, 15 Jul 2026 16:58:33 +0530 Subject: [PATCH] feat: --version flag works on all CLI commands (#125) Previously, OpenAgent Eval v0.4.6 worked but failed with a 'No such option' error because Typer callback options must appear before the subcommand token. Added a wrapper that intercepts / in any position of sys.argv before Typer processes the arguments. Also exported VERSION_OPTION constant from callbacks.py for reuse. Closes #125 --- openagent_eval/cli/main.py | 17 ++++++++++++++++- openagent_eval/cli/utils/callbacks.py | 10 ++++++++++ pyproject.toml | 2 +- 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/openagent_eval/cli/main.py b/openagent_eval/cli/main.py index 4cd0adc..3ef5e1a 100644 --- a/openagent_eval/cli/main.py +++ b/openagent_eval/cli/main.py @@ -7,6 +7,7 @@ import typer from rich.console import Console +from openagent_eval import __version__ from openagent_eval.cli.banner import create_mini_banner from openagent_eval.cli.commands.compare import compare_command from openagent_eval.cli.commands.delete import delete_command @@ -21,7 +22,7 @@ from openagent_eval.cli.commands.validate import validate_command from openagent_eval.cli.commands.audit import audit_command from openagent_eval.cli.context import CLIContext, set_context -from openagent_eval.cli.utils.callbacks import version_callback +from openagent_eval.cli.utils.callbacks import VERSION_OPTION, version_callback from openagent_eval.exceptions import OpenAgentEvalError # Error code mapping for different exception types @@ -475,3 +476,17 @@ def _cli_exception_handler(exc_type: type, exc_value: BaseException, exc_tb: obj # Install custom exception handler sys.excepthook = _cli_exception_handler + + +def _version_aware_cli() -> None: + """CLI entry point that also responds to ``--version`` in subcommand position. + + Typer requires callback options (e.g. ``--version``) to appear *before* + the subcommand token. This wrapper scans ``sys.argv`` so that + ``oaeval run --version`` prints the version and exits. + """ + for token in sys.argv[1:]: + if token in ("--version", "-V"): + typer.echo(f"OpenAgent Eval v{__version__}") + raise SystemExit(0) + app() diff --git a/openagent_eval/cli/utils/callbacks.py b/openagent_eval/cli/utils/callbacks.py index 9825334..d10ec7c 100644 --- a/openagent_eval/cli/utils/callbacks.py +++ b/openagent_eval/cli/utils/callbacks.py @@ -12,3 +12,13 @@ def version_callback(value: bool) -> None: typer.echo(f"OpenAgent Eval v{__version__}") raise typer.Exit() + + +VERSION_OPTION = typer.Option( + False, + "--version", + "-V", + help="Show version and exit.", + callback=version_callback, + is_eager=True, +) diff --git a/pyproject.toml b/pyproject.toml index df022b6..6d73749 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -92,7 +92,7 @@ all = [ ] [project.scripts] -oaeval = "openagent_eval.cli.main:app" +oaeval = "openagent_eval.cli.main:_version_aware_cli" [project.entry-points."openagent_eval.metrics"] # Custom metrics can be registered here