aboutsummaryrefslogtreecommitdiff
path: root/match_file_comment.go
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2026-01-15 21:15:00 +0700
committerShulhan <ms@kilabit.info>2026-01-15 21:23:48 +0700
commitaa7f2df15e91f5c94807247228cf82e18fe03887 (patch)
tree2587dda62755cc69bb785786dd2c80214a23f679 /match_file_comment.go
parent32e4ea9ddf0c2d37f00fa81a4fb1dfe67420b8fe (diff)
downloadspdxconv-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.go29
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
+}