Skip to content

Commit 82279c2

Browse files
authored
Merge pull request #8 from chipfoundry/fix/sync-project-name
Sync project name from platform when linking
2 parents bfe0336 + 8039822 commit 82279c2

1 file changed

Lines changed: 12 additions & 6 deletions

File tree

chipfoundry_cli/main.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3763,12 +3763,18 @@ def _load_project_platform_id(project_root: str):
37633763
return data.get('project', {}).get('platform_project_id')
37643764

37653765

3766-
def _save_platform_id(project_root: str, platform_id: str):
3767-
"""Write platform_project_id into .cf/project.json."""
3766+
def _save_platform_id(project_root: str, platform_id: str, project_name: str = None):
3767+
"""Write platform_project_id (and optionally project name) into .cf/project.json."""
37683768
pj = Path(project_root) / '.cf' / 'project.json'
37693769
with open(pj) as f:
37703770
data = json.load(f)
3771-
data.setdefault('project', {})['platform_project_id'] = platform_id
3771+
proj = data.setdefault('project', {})
3772+
proj['platform_project_id'] = platform_id
3773+
if project_name:
3774+
old_name = proj.get('name')
3775+
proj['name'] = project_name
3776+
if old_name and old_name != project_name:
3777+
console.print(f"[yellow]Updated project name: '{old_name}' → '{project_name}' (synced from platform)[/yellow]")
37723778
with open(pj, 'w') as f:
37733779
json.dump(data, f, indent=2)
37743780

@@ -3800,7 +3806,7 @@ def link_cmd(project_id, project_name):
38003806

38013807
if project_id:
38023808
project = _api_get(f"/projects/{project_id}")
3803-
_save_platform_id(project_root, project['id'])
3809+
_save_platform_id(project_root, project['id'], project['name'])
38043810
portal_url = _get_portal_url()
38053811
console.print(f"[green]✓ Linked to {project['name']}[/green] ({project['id']})")
38063812
console.print(f" Portal: {portal_url}/projects/{project['id']}")
@@ -3817,7 +3823,7 @@ def link_cmd(project_id, project_name):
38173823
console.print(f"[red]No projects matching '{project_name}' found.[/red]")
38183824
return
38193825
if len(matches) == 1:
3820-
_save_platform_id(project_root, matches[0]['id'])
3826+
_save_platform_id(project_root, matches[0]['id'], matches[0]['name'])
38213827
portal_url = _get_portal_url()
38223828
console.print(f"[green]✓ Linked to {matches[0]['name']}[/green] ({matches[0]['id']})")
38233829
console.print(f" Portal: {portal_url}/projects/{matches[0]['id']}")
@@ -3835,7 +3841,7 @@ def link_cmd(project_id, project_name):
38353841
idx = int(choice) - 1
38363842
if 0 <= idx < len(projects):
38373843
selected = projects[idx]
3838-
_save_platform_id(project_root, selected['id'])
3844+
_save_platform_id(project_root, selected['id'], selected['name'])
38393845
portal_url = _get_portal_url()
38403846
console.print(f"\n[green]✓ Linked to {selected['name']}[/green] ({selected['id']})")
38413847
console.print(f" Portal: {portal_url}/projects/{selected['id']}")

0 commit comments

Comments
 (0)