diff options
| author | Shulhan <ms@kilabit.info> | 2026-01-08 04:29:18 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2026-01-08 04:29:18 +0700 |
| commit | 2f6ebacaea7851be5c17a970514769dd3e9735e9 (patch) | |
| tree | d34bcd794ae3946d1a5446e7554ec3cfeaa7c40b /config_match_license.go | |
| parent | 161049a3996c574d521d6d3df55998028eb111c0 (diff) | |
| download | spdxconv-2f6ebacaea7851be5c17a970514769dd3e9735e9.tar.xz | |
all: implement conversion for SPDX-License-Identifier
If the file contains "SPDX-License-Identifier", it will not modify it.
The program will move the identifier to the top of file after shebang.
If the spdxconv.cfg contains match-license, and the pattern match with
one of the line in the file, it will use the license_identifier instead
of default one and insert it at the top, after shebang.
If the files does not contains the identifier, it will insert new one
based on default value in spdxconv.cfg file.
Diffstat (limited to 'config_match_license.go')
| -rw-r--r-- | config_match_license.go | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/config_match_license.go b/config_match_license.go index 11e09fe..c027019 100644 --- a/config_match_license.go +++ b/config_match_license.go @@ -3,7 +3,15 @@ package spdxconv +import ( + "fmt" + "regexp" +) + type configMatchLicense struct { + rePattern *regexp.Regexp + reDeleteLine []*regexp.Regexp + // Pattern to be searched in file. Pattern string `ini:"match-license::pattern"` @@ -21,3 +29,22 @@ type configMatchLicense struct { // be deleted. DeleteMatch bool `ini:"match-license::delete_match"` } + +func (cml *configMatchLicense) init() (err error) { + var logp = `match-license` + if cml.Pattern != `` { + cml.rePattern, err = regexp.Compile(cml.Pattern) + if err != nil { + return fmt.Errorf(`%s: pattern %q: %w`, logp, cml.Pattern, err) + } + } + cml.reDeleteLine = make([]*regexp.Regexp, len(cml.DeleteLinePattern)) + for x, pattern := range cml.DeleteLinePattern { + re, err := regexp.Compile(pattern) + if err != nil { + return fmt.Errorf(`%s: delete_line_pattern %q: %w`, logp, pattern, err) + } + cml.reDeleteLine[x] = re + } + return nil +} |
