diff --git a/src/planecli/commands/projects.py b/src/planecli/commands/projects.py index e0fddda..83f335a 100644 --- a/src/planecli/commands/projects.py +++ b/src/planecli/commands/projects.py @@ -36,6 +36,11 @@ } +def _default_identifier(name: str) -> str: + """Derive a default project identifier from the project name.""" + return "".join(c for c in name if c.isalnum())[:5].upper() + + def _enrich_project(data: dict) -> dict: """Add convenience fields to a project dict.""" network = data.get("network") @@ -157,9 +162,8 @@ async def create( client = get_client() workspace = get_workspace() - create_data = CreateProject(name=name) - if identifier: - create_data.identifier = identifier.upper() + resolved_identifier = (identifier or _default_identifier(name)).upper() + create_data = CreateProject(name=name, identifier=resolved_identifier) if description: create_data.description = description diff --git a/tests/test_projects.py b/tests/test_projects.py new file mode 100644 index 0000000..bbca584 --- /dev/null +++ b/tests/test_projects.py @@ -0,0 +1,19 @@ +"""Tests for the project commands module.""" + +from __future__ import annotations + +from planecli.commands.projects import _default_identifier + + +class TestDefaultIdentifier: + def test_derives_from_name(self): + assert _default_identifier("Frontend App") == "FRONT" + + def test_strips_punctuation(self): + assert _default_identifier("My Backend API!") == "MYBAC" + + def test_keeps_short_name(self): + assert _default_identifier("FE") == "FE" + + def test_uppercases(self): + assert _default_identifier("backend") == "BACKE"