Skip to content
Open
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
10 changes: 7 additions & 3 deletions src/planecli/commands/projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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

Expand Down
19 changes: 19 additions & 0 deletions tests/test_projects.py
Original file line number Diff line number Diff line change
@@ -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"