Skip to content

Commit

Permalink
Use multi-line for current version regexp
Browse files Browse the repository at this point in the history
More useful and probably more expected
  • Loading branch information
wader committed Dec 25, 2023
1 parent e33750f commit 1f596f2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
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

0 comments on commit 1f596f2

Please sign in to comment.