Add --content-only and --rename-only scope flags#47
Conversation
Parse mutually exclusive flags before FIND/REPLACE args. Default behavior rewrites contents and renames paths; each flag limits the operation to one half. README and tests cover all three modes and the both-flags error. Fixes dolph#36 Co-authored-by: Cursor <cursoragent@cursor.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: fc3a1e489a
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| for i < len(args) && strings.HasPrefix(args[i], "-") { | ||
| switch args[i] { | ||
| case "--content-only": | ||
| if scope != scopeAll { | ||
| return findReplace{}, fmt.Errorf("cannot pass both --content-only and --rename-only") | ||
| } | ||
| scope = scopeContentOnly | ||
| case "--rename-only": | ||
| if scope != scopeAll { | ||
| return findReplace{}, fmt.Errorf("cannot pass both --content-only and --rename-only") | ||
| } | ||
| scope = scopeRenameOnly | ||
| default: | ||
| return findReplace{}, fmt.Errorf("unknown flag: %s", args[i]) |
There was a problem hiding this comment.
Allow FIND values that start with '-'
The new argument parser treats every leading dash-prefixed token as a flag and returns unknown flag for anything except the two scope switches, so valid search terms like -foo can no longer be used as FIND (and -- is also rejected). This is a CLI regression from the previous behavior, which accepted any two positional strings; please support an end-of-flags terminator or stop flag parsing once a non-scope token is encountered.
Useful? React with 👍 / 👎.
| func main() { | ||
| // Remove date/time from logging output | ||
| log.SetFlags(0) | ||
| rand.Seed(time.Now().UnixNano()) | ||
|
|
||
| if len(os.Args) != 3 { | ||
| log.Fatal("Usage: find-replace FIND REPLACE") | ||
| fr, err := parseArgs(os.Args[1:]) |
There was a problem hiding this comment.
Restore non-deterministic seeding for temp-name RNG
This change removed startup seeding of math/rand, but File.Write still uses RandomString for temporary file names. Because go.mod targets Go 1.19, the default global RNG stream is deterministic unless seeded, so separate runs can reuse the same temp-name sequence in a directory, increasing cross-run collisions/overwrite races during concurrent use. Reintroduce explicit seeding (or switch temp-name generation to a non-deterministic source).
Useful? React with 👍 / 👎.
Summary
--content-onlyand--rename-onlyflags (mutually exclusive)Fixes #36
Made with Cursor