Skip to content

Commit 8cfa7d1

Browse files
committed
psyflow-init in-place mode check overwrite
1 parent 5247dcd commit 8cfa7d1

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

psyflow/cli.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,22 +50,28 @@ def climain(project_name):
5050
extra_context=extra
5151
)
5252

53-
if not in_place:
54-
# Standard behavior: create a new ./<name> folder
55-
cookiecutter(str(tmpl_dir), output_dir=str(cwd), **cc_kwargs)
56-
return
57-
5853
# 5. In-place mode: render to a temp dir, then copy up
5954
tmp = Path(tempfile.mkdtemp(prefix="psyflow-"))
6055
try:
6156
cookiecutter(str(tmpl_dir), output_dir=str(tmp), **cc_kwargs)
6257
rendered = tmp / name
6358

64-
# Copy everything from rendered/* → cwd/*
59+
overwrite_all = False
6560
for item in rendered.iterdir():
6661
dest = cwd / item.name
62+
63+
# if dest already exists, ask once whether to overwrite everything
64+
if dest.exists() and not overwrite_all:
65+
resp = input(f"⚠ Existing '{item.name}' detected. Overwrite this and all remaining? [y/N]: ").strip().lower()
66+
if resp == 'y':
67+
overwrite_all = True
68+
else:
69+
print(f" Skipping '{item.name}'")
70+
continue
71+
72+
# Copy the item (dirs_exist_ok only matters for directories)
6773
if item.is_dir():
68-
shutil.copytree(item, dest, dirs_exist_ok=True)
74+
shutil.copytree(item, dest, dirs_exist_ok=overwrite_all)
6975
else:
7076
shutil.copy2(item, dest)
7177

0 commit comments

Comments
 (0)