Skip to content

Commit 765b2cb

Browse files
authored
✨ Add a confirmation step to the first CLI deployment (#140)
1 parent 9a6fa98 commit 765b2cb

File tree

2 files changed

+70
-5
lines changed

2 files changed

+70
-5
lines changed

src/fastapi_cloud_cli/commands/deploy.py

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,8 @@ def _configure_app(toolkit: RichToolkit, path_to_deploy: Path) -> AppConfig:
295295

296296
toolkit.print_line()
297297

298+
selected_app: AppResponse | None = None
299+
298300
if not create_new_app:
299301
with toolkit.progress("Fetching apps...") as progress:
300302
with handle_http_errors(
@@ -311,18 +313,45 @@ def _configure_app(toolkit: RichToolkit, path_to_deploy: Path) -> AppConfig:
311313

312314
raise typer.Exit(1)
313315

314-
app = toolkit.ask(
316+
selected_app = toolkit.ask(
315317
"Select the app you want to deploy to:",
316318
options=[Option({"name": app.slug, "value": app}) for app in apps],
317319
)
318-
else:
319-
app_name = toolkit.input(
320+
321+
app_name = (
322+
selected_app.slug
323+
if selected_app
324+
else toolkit.input(
320325
title="What's your app name?",
321326
default=_get_app_name(path_to_deploy),
322327
)
328+
)
323329

324-
toolkit.print_line()
330+
toolkit.print_line()
331+
332+
toolkit.print("Deployment configuration:", tag="summary")
333+
toolkit.print_line()
334+
toolkit.print(f"Team: [bold]{team.name}[/bold]")
335+
toolkit.print(f"App name: [bold]{app_name}[/bold]")
336+
toolkit.print_line()
325337

338+
choice = toolkit.ask(
339+
"Does everything look right?",
340+
tag="confirm",
341+
options=[
342+
Option({"name": "Yes, start the deployment!", "value": "deploy"}),
343+
Option({"name": "No, let me start over", "value": "cancel"}),
344+
],
345+
)
346+
toolkit.print_line()
347+
348+
if choice == "cancel":
349+
toolkit.print("Deployment cancelled.")
350+
raise typer.Exit(0)
351+
352+
if selected_app: # pragma: no cover
353+
app = selected_app
354+
else:
326355
with toolkit.progress(title="Creating app...") as progress:
327356
with handle_http_errors(progress):
328357
app = _create_app(team.id, app_name)

tests/test_cli_deploy.py

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ def test_asks_for_app_name_after_team(
316316
def test_creates_app_on_backend(
317317
logged_in_cli: None, tmp_path: Path, respx_mock: respx.MockRouter
318318
) -> None:
319-
steps = [Keys.ENTER, Keys.ENTER, *"demo", Keys.ENTER]
319+
steps = [Keys.ENTER, Keys.ENTER, *"demo", Keys.ENTER, Keys.ENTER]
320320

321321
team = _get_random_team()
322322

@@ -344,6 +344,40 @@ def test_creates_app_on_backend(
344344
assert "App created successfully" in result.output
345345

346346

347+
@pytest.mark.respx(base_url=settings.base_api_url)
348+
def test_cancels_deployment_when_user_selects_no(
349+
logged_in_cli: None, tmp_path: Path, respx_mock: respx.MockRouter
350+
) -> None:
351+
steps = [
352+
Keys.ENTER,
353+
Keys.ENTER,
354+
*"demo",
355+
Keys.ENTER,
356+
Keys.DOWN_ARROW,
357+
Keys.ENTER,
358+
]
359+
360+
team = _get_random_team()
361+
362+
respx_mock.get("/teams/").mock(
363+
return_value=Response(
364+
200,
365+
json={"data": [team]},
366+
)
367+
)
368+
369+
with (
370+
changing_dir(tmp_path),
371+
patch("rich_toolkit.container.getchar") as mock_getchar,
372+
):
373+
mock_getchar.side_effect = steps
374+
375+
result = runner.invoke(app, ["deploy"])
376+
377+
assert result.exit_code == 0
378+
assert "Deployment cancelled." in result.output
379+
380+
347381
@pytest.mark.respx(base_url=settings.base_api_url)
348382
def test_uses_existing_app(
349383
logged_in_cli: None, tmp_path: Path, respx_mock: respx.MockRouter
@@ -383,6 +417,7 @@ def test_exits_successfully_when_deployment_is_done(
383417
Keys.ENTER,
384418
*"demo",
385419
Keys.ENTER,
420+
Keys.ENTER,
386421
]
387422

388423
team_data = _get_random_team()
@@ -633,6 +668,7 @@ def _deploy_without_waiting(respx_mock: respx.MockRouter, tmp_path: Path) -> Res
633668
Keys.ENTER,
634669
*"demo",
635670
Keys.ENTER,
671+
Keys.ENTER,
636672
]
637673

638674
team_data = _get_random_team()

0 commit comments

Comments
 (0)