From d4298c231201307d334f0d73b38fcf5593d039a8 Mon Sep 17 00:00:00 2001 From: Patrick Arminio Date: Mon, 22 Jun 2026 10:32:49 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Handle=20invalid=20apps=20create?= =?UTF-8?q?=20--directory=20input?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Shortcake-Parent: main --- src/fastapi_cloud_cli/commands/apps/create.py | 17 +++++++++-- tests/test_cli_apps.py | 30 +++++++++++++++++++ 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/src/fastapi_cloud_cli/commands/apps/create.py b/src/fastapi_cloud_cli/commands/apps/create.py index 00c93c4b..fa4f3df8 100644 --- a/src/fastapi_cloud_cli/commands/apps/create.py +++ b/src/fastapi_cloud_cli/commands/apps/create.py @@ -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[ @@ -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", diff --git a/tests/test_cli_apps.py b/tests/test_cli_apps.py index 47a4cad2..770c3a96 100644 --- a/tests/test_cli_apps.py +++ b/tests/test_cli_apps.py @@ -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,