Skip to content

Commit 340ceca

Browse files
authored
🐛 Handle invalid apps create --directory input (#265)
1 parent 8ee22ad commit 340ceca

2 files changed

Lines changed: 45 additions & 2 deletions

File tree

src/fastapi_cloud_cli/commands/apps/create.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,10 @@ def create_app(
7575
str | None,
7676
typer.Option(
7777
"--directory",
78-
help="Directory containing the app's pyproject.toml.",
78+
help=(
79+
"Relative app directory containing the pyproject.toml "
80+
"(for example: src or backend)."
81+
),
7982
),
8083
] = None,
8184
link: Annotated[
@@ -146,7 +149,17 @@ def create_app(
146149
)
147150
toolkit.print_line()
148151

149-
directory = validate_app_directory(directory)
152+
try:
153+
directory = validate_app_directory(directory)
154+
except ValueError as e:
155+
toolkit.fail(
156+
"invalid_input",
157+
f"Invalid app directory: {e}",
158+
hint=(
159+
"Pass a relative app directory such as `src` or `backend`; "
160+
"use --path with --link to choose a local filesystem path."
161+
),
162+
)
150163

151164
with toolkit.progress(
152165
title="Creating app",

tests/test_cli_apps.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,36 @@ def test_creates_app_json_rejects_path_without_link(
322322
assert result.stderr == ""
323323

324324

325+
def test_creates_app_json_rejects_invalid_directory(logged_in_cli: None) -> None:
326+
result = runner.invoke(
327+
app,
328+
[
329+
"apps",
330+
"create",
331+
"--team-id",
332+
"00000000-0000-4000-8000-000000000001",
333+
"--name",
334+
"API",
335+
"--directory",
336+
"/tmp/api",
337+
"--json",
338+
],
339+
)
340+
341+
assert result.exit_code == 1
342+
assert json.loads(result.stdout) == {
343+
"error": {
344+
"code": "invalid_input",
345+
"message": ("Invalid app directory: must be a relative path, not absolute"),
346+
"hint": (
347+
"Pass a relative app directory such as `src` or `backend`; "
348+
"use --path with --link to choose a local filesystem path."
349+
),
350+
}
351+
}
352+
assert result.stderr == ""
353+
354+
325355
@pytest.mark.respx
326356
def test_links_existing_app_to_path_as_json(
327357
logged_in_cli: None,

0 commit comments

Comments
 (0)