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
16 changes: 13 additions & 3 deletions src/zad_cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class _GlobalOptionsGroup(TyperGroup):
"""Hoist global options to before the subcommand so they work in any position."""

_OPTS_WITH_VALUE = frozenset({"--output", "-o", "--api-key", "--api-url", "--project", "-p"})
_FLAGS = frozenset({"--no-wait", "--verbose", "-v"})
_FLAGS = frozenset({"--no-wait", "--verbose", "-v", "--version", "-V"})

def parse_args(self, ctx, args): # noqa: ANN001
global_args: list[str] = []
Expand Down Expand Up @@ -79,6 +79,12 @@ def parse_args(self, ctx, args): # noqa: ANN001
app.add_typer(open_app, name="open")


def _version_callback(value: bool) -> None:
if value:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Minor: print() bypasses Typer's output handling. Prefer typer.echo(f"zad-cli {__version__}") for consistency with Typer conventions and to respect NO_COLOR/TERM env vars. (The existing deprecated version command also uses print(), so this is at least internally consistent — but worth cleaning both up together.)

print(f"zad-cli {__version__}")
raise typer.Exit()


@app.callback()
def main_callback(
ctx: typer.Context,
Expand All @@ -88,6 +94,9 @@ def main_callback(
project_id: str = typer.Option(None, "--project", "-p", envvar="ZAD_PROJECT_ID", help="Project ID"),
no_wait: bool = typer.Option(False, "--no-wait", help="Don't wait for async operations, return task ID"),
verbose: bool = typer.Option(False, "--verbose", "-v", help="Enable verbose request logging"),
version: bool = typer.Option(
False, "--version", "-V", help="Show version and exit", callback=_version_callback, is_eager=True
),
) -> None:
"""Global options applied to all commands."""
from zad_cli.output.formatter import OutputFormatter
Expand All @@ -102,9 +111,10 @@ def main_callback(
ctx.obj["no_wait"] = no_wait


@app.command()
@app.command(deprecated=True)
def version() -> None:
"""Show version information."""
"""[Deprecated] Use `zad --version` instead."""
typer.echo("Warning: `zad version` is deprecated, use `zad --version` instead.", err=True)
print(f"zad-cli {__version__}")


Expand Down
14 changes: 13 additions & 1 deletion tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,18 @@ def test_help_exits_zero():
assert "--verbose" in out


def test_version():
def test_version_flag():
result = subprocess.run(
[sys.executable, "-m", "zad_cli", "--version"],
capture_output=True,
text=True,
env=_PLAIN_ENV,
)
assert result.returncode == 0
assert "zad-cli" in result.stdout


def test_version_subcommand_deprecated():
result = subprocess.run(
[sys.executable, "-m", "zad_cli", "version"],
capture_output=True,
Expand All @@ -45,6 +56,7 @@ def test_version():
)
assert result.returncode == 0
assert "zad-cli" in result.stdout
assert "deprecated" in result.stderr.lower()


def test_project_help_without_api_key():
Expand Down
Loading