🐛 fix make init to support re-initialization#145
Conversation
The init target used hardcoded default strings so it silently failed when run on an already-renamed project. Now reads current name and description from pyproject.toml dynamically. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Greptile SummaryThis PR makes
Confidence Score: 4/5
Important Files Changed
Prompt To Fix All With AIThis is a comment left during a code review.
Path: Makefile
Line: 46-47
Comment:
**Silent failure when extraction returns empty**
If `pyproject.toml` is missing, or if either field isn't present in the exact format `^name = "…"` (e.g., TOML allows `name="…"` without spaces), `CURRENT_NAME` and/or `CURRENT_DESC` will be empty strings. The downstream sed commands will then attempt to match `name = ""` or `description = ""`, find nothing, exit 0, and leave the files silently unchanged — with no indication to the user that the rename failed.
Consider adding an explicit guard after each extraction:
```
CURRENT_NAME=$$(sed -n 's/^name = "\(.*\)"/\1/p' pyproject.toml | head -1); \
if [ -z "$$CURRENT_NAME" ]; then echo "$(RED)Error: could not read current name from pyproject.toml$(RESET)"; exit 1; fi; \
CURRENT_DESC=$$(sed -n 's/^description = "\(.*\)"/\1/p' pyproject.toml | head -1); \
if [ -z "$$CURRENT_DESC" ]; then echo "$(RED)Error: could not read current description from pyproject.toml$(RESET)"; exit 1; fi; \
```
How can I resolve this? If you propose a fix, please make it concise.Last reviewed commit: 71cac05 |
Address review feedback: - Escape regex special chars in extracted name/description before using them in sed patterns - Restrict <b> tag replacement to first 10 lines of README to avoid clobbering unrelated bold markup Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
Addressed both review comments in 179189d:
|
New name/description values also need escaping for sed replacement special chars (& / | \) to handle names like "acme/my-project" or descriptions containing "&". Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
Addressed in 0c144f3 — new values (
So |
ESC_NEW_DESC is used in both a /-delimited sed (pyproject.toml) and a |-delimited sed (README), so it needs to escape both delimiters. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
Fixed in 71cac05 — added |
| @CURRENT_NAME=$$(sed -n 's/^name = "\(.*\)"/\1/p' pyproject.toml | head -1); \ | ||
| CURRENT_DESC=$$(sed -n 's/^description = "\(.*\)"/\1/p' pyproject.toml | head -1); \ |
There was a problem hiding this comment.
Silent failure when extraction returns empty
If pyproject.toml is missing, or if either field isn't present in the exact format ^name = "…" (e.g., TOML allows name="…" without spaces), CURRENT_NAME and/or CURRENT_DESC will be empty strings. The downstream sed commands will then attempt to match name = "" or description = "", find nothing, exit 0, and leave the files silently unchanged — with no indication to the user that the rename failed.
Consider adding an explicit guard after each extraction:
CURRENT_NAME=$$(sed -n 's/^name = "\(.*\)"/\1/p' pyproject.toml | head -1); \
if [ -z "$$CURRENT_NAME" ]; then echo "$(RED)Error: could not read current name from pyproject.toml$(RESET)"; exit 1; fi; \
CURRENT_DESC=$$(sed -n 's/^description = "\(.*\)"/\1/p' pyproject.toml | head -1); \
if [ -z "$$CURRENT_DESC" ]; then echo "$(RED)Error: could not read current description from pyproject.toml$(RESET)"; exit 1; fi; \
Prompt To Fix With AI
This is a comment left during a code review.
Path: Makefile
Line: 46-47
Comment:
**Silent failure when extraction returns empty**
If `pyproject.toml` is missing, or if either field isn't present in the exact format `^name = "…"` (e.g., TOML allows `name="…"` without spaces), `CURRENT_NAME` and/or `CURRENT_DESC` will be empty strings. The downstream sed commands will then attempt to match `name = ""` or `description = ""`, find nothing, exit 0, and leave the files silently unchanged — with no indication to the user that the rename failed.
Consider adding an explicit guard after each extraction:
```
CURRENT_NAME=$$(sed -n 's/^name = "\(.*\)"/\1/p' pyproject.toml | head -1); \
if [ -z "$$CURRENT_NAME" ]; then echo "$(RED)Error: could not read current name from pyproject.toml$(RESET)"; exit 1; fi; \
CURRENT_DESC=$$(sed -n 's/^description = "\(.*\)"/\1/p' pyproject.toml | head -1); \
if [ -z "$$CURRENT_DESC" ]; then echo "$(RED)Error: could not read current description from pyproject.toml$(RESET)"; exit 1; fi; \
```
How can I resolve this? If you propose a fix, please make it concise.|
Closing — |
Summary
make initused hardcoded strings ("python-template","Add your description here", etc.) so it silently failed when run on an already-renamed projectpyproject.tomlbefore replacing, makingmake initidempotent and re-runnableMirrors the fix in Miyamura80/CLI-Template#21
Test plan
make init name=foo description="bar"on a fresh template — verify pyproject.toml and README updatemake init name=baz description="qux"again — verify it re-renames correctly🤖 Generated with Claude Code