Skip to content

Commit a756501

Browse files
committed
Add --version option
1 parent dbeacda commit a756501

2 files changed

Lines changed: 38 additions & 0 deletions

File tree

src/fastapi_cloud_cli/cli.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1+
from typing import Annotated
2+
13
import typer
4+
from rich import print
25

6+
from . import __version__
37
from .commands.deploy import deploy
48
from .commands.env import env_app
59
from .commands.link import link
@@ -16,11 +20,33 @@
1620

1721
app = typer.Typer(rich_markup_mode="rich")
1822

23+
24+
def version_callback(value: bool) -> None:
25+
if value:
26+
print(f"FastAPI Cloud CLI version: [green]{__version__}[/green]")
27+
raise typer.Exit()
28+
29+
1930
cloud_app = typer.Typer(
2031
rich_markup_mode="rich",
2132
help="Manage [bold]FastAPI[/bold] Cloud deployments. 🚀",
2233
)
2334

35+
36+
@cloud_app.callback()
37+
def cloud_main(
38+
version: Annotated[
39+
bool,
40+
typer.Option(
41+
"--version",
42+
callback=version_callback,
43+
is_eager=True,
44+
help="Show the version and exit.",
45+
),
46+
] = False,
47+
) -> None: ...
48+
49+
2450
# TODO: use the app structure
2551

2652
# Additional commands

tests/test_cli.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
import subprocess
22
import sys
33

4+
from typer.testing import CliRunner
5+
6+
from fastapi_cloud_cli.cli import cloud_app as app
7+
8+
runner = CliRunner()
9+
410

511
def test_script() -> None:
612
result = subprocess.run(
@@ -9,3 +15,9 @@ def test_script() -> None:
915
encoding="utf-8",
1016
)
1117
assert "Usage" in result.stdout
18+
19+
20+
def test_version() -> None:
21+
result = runner.invoke(app, ["--version"])
22+
assert result.exit_code == 0, result.output
23+
assert "FastAPI Cloud CLI version:" in result.output

0 commit comments

Comments
 (0)