diff --git a/src/fastapi_cloud_cli/cli.py b/src/fastapi_cloud_cli/cli.py index 555119f..d2a8052 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,12 +20,34 @@ 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. 🚀", no_args_is_help=True, ) + +@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 8440b7a..0f068c7 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -29,3 +29,9 @@ def test_script() -> None: encoding="utf-8", ) assert "Usage" in result.stdout + + +def test_version() -> None: + result = runner.invoke(app, ["cloud", "--version"]) + assert result.exit_code == 0, result.output + assert "FastAPI Cloud CLI version:" in result.output