diff options
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 +} |
