Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions src/fastapi_cloud_cli/commands/apps/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,10 @@ def create_app(
str | None,
typer.Option(
"--directory",
help="Directory containing the app's pyproject.toml.",
help=(
"Relative app directory containing the pyproject.toml "
"(for example: src or backend)."
),
),
] = None,
link: Annotated[
Expand Down Expand Up @@ -146,7 +149,17 @@ def create_app(
)
toolkit.print_line()

directory = validate_app_directory(directory)
try:
directory = validate_app_directory(directory)
except ValueError as e:
toolkit.fail(
"invalid_input",
f"Invalid app directory: {e}",
hint=(
"Pass a relative app directory such as `src` or `backend`; "
"use --path with --link to choose a local filesystem path."
),
)

with toolkit.progress(
title="Creating app",
Expand Down
30 changes: 30 additions & 0 deletions tests/test_cli_apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,36 @@ def test_creates_app_json_rejects_path_without_link(
assert result.stderr == ""


def test_creates_app_json_rejects_invalid_directory(logged_in_cli: None) -> None:
result = runner.invoke(
app,
[
"apps",
"create",
"--team-id",
"00000000-0000-4000-8000-000000000001",
"--name",
"API",
"--directory",
"/tmp/api",
"--json",
],
)

assert result.exit_code == 1
assert json.loads(result.stdout) == {
"error": {
"code": "invalid_input",
"message": ("Invalid app directory: must be a relative path, not absolute"),
"hint": (
"Pass a relative app directory such as `src` or `backend`; "
"use --path with --link to choose a local filesystem path."
),
}
}
assert result.stderr == ""


@pytest.mark.respx
def test_links_existing_app_to_path_as_json(
logged_in_cli: None,
Expand Down