Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use multi-line for current version regexp #135

Merged
merged 1 commit into from
Dec 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions internal/bump/fileset.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type Check struct {

// bump: <name> /<re>/ <pipeline>
PipelineLineNr int
CurrentREStr string
CurrentRE *regexp.Regexp
Pipeline pipeline.Pipeline
PipelineDuration time.Duration
Expand Down Expand Up @@ -80,7 +81,7 @@ type Current struct {
}

func (c *Check) String() string {
return fmt.Sprintf("%s /%s/ %s", c.Name, c.CurrentRE, c.Pipeline)
return fmt.Sprintf("%s /%s/ %s", c.Name, c.CurrentREStr, c.Pipeline)
}

// FileSet is a set of File:s, filters and checks found in files
Expand Down Expand Up @@ -443,7 +444,8 @@ func (fs *FileSet) parseCheckLine(file *File, lineNr int, line string, filters [
if err != nil {
return fmt.Errorf("%s: %w", pipelineStr, err)
}
currentRe, err := regexp.Compile(currentReStr)
// compile in multi-line mode: ^$ matches end/start of line
currentRe, err := regexp.Compile("(?m)" + currentReStr)
if err != nil {
return fmt.Errorf("invalid current version regexp: %q", currentReStr)
}
Expand All @@ -454,6 +456,7 @@ func (fs *FileSet) parseCheckLine(file *File, lineNr int, line string, filters [
check := &Check{
File: file,
Name: name,
CurrentREStr: currentReStr,
CurrentRE: currentRe,
PipelineLineNr: lineNr,
Pipeline: pl,
Expand Down
2 changes: 1 addition & 1 deletion internal/cli/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ func parseTestCases(s string) []testCase {
tc := testCase{}
seenRun := false

for _, section := range sectionParser(regexp.MustCompile(`^([/>].*:)|[#\$!].*$`), c) {
for _, section := range sectionParser(regexp.MustCompile(`^([/>].*:)|^[#\$!].*$`), c) {
n, v := section.Name, section.Value

switch {
Expand Down
6 changes: 6 additions & 0 deletions internal/cli/testdata/bumpfile_match_line_end
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/a:
bump: name /^name: (1)$/ static:2
name: 1
$ bump current a
>stdout:
a:2: name 1
Loading