diff --git a/src/drs/cli.py b/src/drs/cli.py index 8a86e4d..346ed1f 100644 --- a/src/drs/cli.py +++ b/src/drs/cli.py @@ -26,6 +26,7 @@ import httpx import typer +from drs import __version__ from drs.auth import DrsConfig, load_config from drs.client import DremioClient from drs.commands import ( @@ -49,7 +50,7 @@ app = typer.Typer( name="dremio", - help="Developer CLI for Dremio Cloud.", + help=f"Developer CLI for Dremio Cloud (version {__version__})", no_args_is_help=True, context_settings=CONTEXT_SETTINGS, ) @@ -75,9 +76,18 @@ _cli_opts: dict = {} +def _version_callback(value: bool) -> None: + if value: + print(f"dremio-cli {__version__}") + raise typer.Exit() + + @app.callback() def main( ctx: typer.Context, + version: bool = typer.Option( + False, "--version", help="Show version and exit.", callback=_version_callback, is_eager=True + ), config: str | None = typer.Option(None, "--config", "-c", help="Path to config file"), token: str | None = typer.Option(None, "--token", help="Dremio personal access token (PAT)"), project_id: str | None = typer.Option(None, "--project-id", help="Dremio Cloud project ID"), diff --git a/tests/test_cli.py b/tests/test_cli.py new file mode 100644 index 0000000..0f6cd3a --- /dev/null +++ b/tests/test_cli.py @@ -0,0 +1,43 @@ +# +# Copyright (C) 2017-2026 Dremio Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +"""Tests for CLI --version and --help flags.""" + +from __future__ import annotations + +from typer.testing import CliRunner + +from drs import __version__ +from drs.cli import app + +runner = CliRunner() + + +def test_version_flag() -> None: + result = runner.invoke(app, ["--version"]) + assert result.exit_code == 0 + assert f"dremio-cli {__version__}" in result.output + + +def test_help_includes_version() -> None: + result = runner.invoke(app, ["--help"]) + assert result.exit_code == 0 + assert f"(version {__version__})" in result.output + + +def test_help_short_flag() -> None: + result = runner.invoke(app, ["-h"]) + assert result.exit_code == 0 + assert f"(version {__version__})" in result.output