Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/drs/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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,
)
Expand All @@ -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"),
Expand Down
43 changes: 43 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -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