Skip to content

Commit 6ad4cbe

Browse files
Robust project scaffolding in start command with better error reporting
1 parent 8d84442 commit 6ad4cbe

1 file changed

Lines changed: 20 additions & 8 deletions

File tree

pythoncms/cli.py

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"""
1616
import os
1717
import secrets
18+
import shutil
1819
import subprocess
1920
import sys
2021
from pathlib import Path
@@ -41,20 +42,31 @@ def cli():
4142
@click.option("--run", is_flag=True, help="Initialize and run the server immediately")
4243
def start(name, run):
4344
"""Create a new pythoncms project"""
44-
# Use PWD environment variable if available to handle deleted CWD
45-
base_dir = os.environ.get("PWD") or os.getcwd()
46-
dest = os.path.join(base_dir, name)
45+
# Bulletproof path resolution
46+
try:
47+
dest = os.path.abspath(name)
48+
except FileNotFoundError:
49+
# Fallback for deleted CWD
50+
base_dir = os.environ.get("PWD") or os.getcwd()
51+
dest = os.path.join(base_dir, name)
52+
53+
click.echo(f"📂 Creating project at: {dest}")
4754

4855
if os.path.exists(dest):
49-
click.echo(f"Error: Directory {name} already exists.")
56+
click.echo(f"Error: Directory already exists at {dest}")
5057
return
5158

59+
# Ensure parent directory exists
60+
os.makedirs(os.path.dirname(dest), exist_ok=True)
5261

5362
# Copy the project structure
54-
trycopytree(str(path.parent.absolute()), dest)
55-
56-
# Cleanup target
57-
tryrmfile(os.path.join(dest, "cli.py"))
63+
source_dir = str(path.parent.absolute())
64+
try:
65+
shutil.copytree(source_dir, dest, ignore=shutil.ignore_patterns('__pycache__', 'cli.py', '*.db', 'instance'))
66+
click.echo(f"✅ Scaffolding complete in {dest}")
67+
except Exception as e:
68+
click.echo(f"❌ Error during scaffolding: {e}")
69+
return
5870

5971
# Create requirements.txt
6072
reqs = f"pythoncms=={__version__}"

0 commit comments

Comments
 (0)