From a75650188ef096bcb028e01a13b8d00fb77f5fc6 Mon Sep 17 00:00:00 2001 From: Yurii Motov Date: Tue, 17 Mar 2026 20:01:10 +0100 Subject: [PATCH] Add `--version` option --- src/fastapi_cloud_cli/cli.py | 26 ++++++++++++++++++++++++++ tests/test_cli.py | 12 ++++++++++++ 2 files changed, 38 insertions(+) diff --git a/src/fastapi_cloud_cli/cli.py b/src/fastapi_cloud_cli/cli.py index 3fb70800..3564c845 100644 --- a/src/fastapi_cloud_cli/cli.py +++ b/src/fastapi_cloud_cli/cli.py @@ -1,5 +1,9 @@ +from typing import Annotated + import typer +from rich import print +from . import __version__ from .commands.deploy import deploy from .commands.env import env_app from .commands.link import link @@ -16,11 +20,33 @@ app = typer.Typer(rich_markup_mode="rich") + +def version_callback(value: bool) -> None: + if value: + print(f"FastAPI Cloud CLI version: [green]{__version__}[/green]") + raise typer.Exit() + + cloud_app = typer.Typer( rich_markup_mode="rich", help="Manage [bold]FastAPI[/bold] Cloud deployments. 🚀", ) + +@cloud_app.callback() +def cloud_main( + version: Annotated[ + bool, + typer.Option( + "--version", + callback=version_callback, + is_eager=True, + help="Show the version and exit.", + ), + ] = False, +) -> None: ... + + # TODO: use the app structure # Additional commands diff --git a/tests/test_cli.py b/tests/test_cli.py index 2e433309..9734787c 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -1,6 +1,12 @@ import subprocess import sys +from typer.testing import CliRunner + +from fastapi_cloud_cli.cli import cloud_app as app + +runner = CliRunner() + def test_script() -> None: result = subprocess.run( @@ -9,3 +15,9 @@ def test_script() -> None: encoding="utf-8", ) assert "Usage" in result.stdout + + +def test_version() -> None: + result = runner.invoke(app, ["--version"]) + assert result.exit_code == 0, result.output + assert "FastAPI Cloud CLI version:" in result.output