Skip to content

feat: add -e/--regex opt-in pattern mode#101

Open
leno23 wants to merge 2 commits into
dolph:mainfrom
leno23:feat/regex-flag-issue-38-v2
Open

feat: add -e/--regex opt-in pattern mode#101
leno23 wants to merge 2 commits into
dolph:mainfrom
leno23:feat/regex-flag-issue-38-v2

Conversation

@leno23
Copy link
Copy Markdown

@leno23 leno23 commented May 31, 2026

Summary

Notes

Fixes #38

Test plan

  • go test ./...
  • TestRun_RegexModeRewritesContent\d+NUM
  • TestRun_RegexModeRenamesFiles(\w+)_test\.go$1.test.go
  • TestRun_InvalidRegexExitsNonZero

Made with Cursor

leno23 added 2 commits May 31, 2026 19:39
Introduce Pattern with literal mode (QuoteMeta) wired into content and
rename paths so capture-group replacement can land without changing CLI
behavior today.

Fixes dolph#37
Expose regex matching via -e/--regex while keeping literal mode as the
default. Invalid patterns fail at startup with a compile error.

Depends on dolph#37; merge after dolph#35 and dolph#36 land. v2.0.0 docs/version bump
follows separately.

Fixes dolph#38
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6c2aa4962a

ℹ️ 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".

Comment thread pattern.go
}

func (p *Pattern) Replace(s string) string {
return p.re.ReplaceAllString(s, p.replace)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Preserve dollar literals in default replacements

In the default non-regex mode, replacements containing $ are now interpreted by regexp.ReplaceAllString as capture expansions, so an invocation like find-replace foo '$1' rewrites each foo to an empty string, and price $5 drops $5. Literal mode previously used strings.ReplaceAll, so these replacement bytes were preserved; this can silently corrupt both file contents and renamed paths unless literal mode uses a literal replacement path.

Useful? React with 👍 / 👎.

Comment thread find_replace.go
if err != nil {
return err
}
fr.pattern = p
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Guard lazy pattern initialization across walkers

When findReplace is used directly without run's eager ensurePattern call, as the existing tests and benchmark constructors do, WalkDir starts multiple goroutines and each can call ensurePattern through HandleFile, racing on fr.pattern. This violates the repo's required go test -race ./... discipline and can be fixed by compiling before fan-out or protecting initialization with sync.Once/a mutex.

Useful? React with 👍 / 👎.

Comment thread find_replace.go
Comment on lines +92 to +93
case "-e", "--regex":
regex = true
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Document the new regex flag in the README

This adds the -e/--regex CLI surface, but the repo guide explicitly requires updating the README in the same PR whenever a flag or subcommand is added. Without that documentation update, the advertised CLI contract remains stale and users will not see the new mode or its replacement semantics.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add -e/--regex opt-in mode — triggers v2.0.0 release

1 participant