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,