diff options
| author | Shulhan <ms@kilabit.info> | 2026-01-15 21:15:00 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2026-01-15 21:23:48 +0700 |
| commit | aa7f2df15e91f5c94807247228cf82e18fe03887 (patch) | |
| tree | 2587dda62755cc69bb785786dd2c80214a23f679 /match_file_comment.go | |
| parent | 32e4ea9ddf0c2d37f00fa81a4fb1dfe67420b8fe (diff) | |
| download | spdxconv-aa7f2df15e91f5c94807247228cf82e18fe03887.tar.xz | |
all: allow multiple pattern in match-file-comment
This makes the configuration more concise where pattern can be split
into multi lines.
While at it, add more pattern to match-file-comment.
Diffstat (limited to 'match_file_comment.go')
| -rw-r--r-- | match_file_comment.go | 29 |
1 files changed, 21 insertions, 8 deletions
diff --git a/match_file_comment.go b/match_file_comment.go index e5b4233..90ce22e 100644 --- a/match_file_comment.go +++ b/match_file_comment.go @@ -14,19 +14,22 @@ import ( // File name that have empty Prefix and Suffix and match with the pattern will // have the ".license" file created. type matchFileComment struct { - rePattern *regexp.Regexp + Prefix string `ini:"match-file-comment::prefix"` + Suffix string `ini:"match-file-comment::suffix"` - Pattern string `ini:"match-file-comment::pattern"` - Prefix string `ini:"match-file-comment::prefix"` - Suffix string `ini:"match-file-comment::suffix"` + Pattern []string `ini:"match-file-comment::pattern"` + rePattern []*regexp.Regexp } func (mfc *matchFileComment) init() (err error) { var logp = `match-file-comment` - - mfc.rePattern, err = regexp.Compile(mfc.Pattern) - if err != nil { - return fmt.Errorf(`%s: pattern %q: %w`, logp, mfc.Pattern, err) + var re *regexp.Regexp + for _, pattern := range mfc.Pattern { + re, err = regexp.Compile(pattern) + if err != nil { + return fmt.Errorf(`%s: pattern %q: %w`, logp, pattern, err) + } + mfc.rePattern = append(mfc.rePattern, re) } return nil } @@ -34,3 +37,13 @@ func (mfc *matchFileComment) init() (err error) { func (mfc *matchFileComment) isDirectLicense() bool { return mfc.Prefix == `` && mfc.Suffix == `` } + +// isMatch return true if the filename match with one of the pattern. +func (mfc *matchFileComment) isMatch(filename string) bool { + for _, re := range mfc.rePattern { + if re.MatchString(filename) { + return true + } + } + return false +} |
