generated from coulomb/repo-seed
fix(cli): auto-create topic when registering a brand-new domain
register-project now creates a topic automatically if the domain has no active topic yet, instead of exiting with an error. This makes the "create domain → register project" flow self-contained. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -97,13 +97,24 @@ def cmd_register(args: argparse.Namespace) -> None:
|
|||||||
print(f"ERROR: Unknown domain '{domain}'. Valid: {', '.join(valid_domains)}")
|
print(f"ERROR: Unknown domain '{domain}'. Valid: {', '.join(valid_domains)}")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
# ── Step 3: Topic ID lookup ────────────────────────────────────────────────
|
# ── Step 3: Topic ID lookup (auto-create if new domain) ───────────────────
|
||||||
print(f"==> Looking up topic for domain '{domain}' ...")
|
print(f"==> Looking up topic for domain '{domain}' ...")
|
||||||
topics = _api_get("/topics/?status=active")
|
topics = _api_get("/topics/?status=active")
|
||||||
match = next((t for t in topics if t.get("domain_slug") == domain), None)
|
match = next((t for t in topics if t.get("domain_slug") == domain), None)
|
||||||
if not match:
|
if not match:
|
||||||
print(f"ERROR: No active topic found for domain '{domain}'.")
|
print(f" No topic found — creating one for domain '{domain}' ...")
|
||||||
sys.exit(1)
|
slug = re.sub(r"[^a-z0-9]+", "-", domain.lower()).strip("-")
|
||||||
|
try:
|
||||||
|
match = _api_post("/topics/", {
|
||||||
|
"slug": slug,
|
||||||
|
"title": project_name,
|
||||||
|
"domain": domain,
|
||||||
|
"status": "active",
|
||||||
|
})
|
||||||
|
print(f" Topic created: {match['title']} ({match['id']})")
|
||||||
|
except Exception as e:
|
||||||
|
print(f"ERROR: Could not create topic for domain '{domain}': {e}")
|
||||||
|
sys.exit(1)
|
||||||
topic_id = match["id"]
|
topic_id = match["id"]
|
||||||
print(f" topic_id: {topic_id}")
|
print(f" topic_id: {topic_id}")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user