Skip to content

Commit

Permalink
Allow rules like :
Browse files Browse the repository at this point in the history
 - Dockerfile* to match all dockerfiles in direcotry
  • Loading branch information
kuritka committed Mar 15, 2021
1 parent 772c4d1 commit f7e2a79
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ create `.licignore`
And run **GOLIC**
```shell
# GO 1.16
go install github.com/AbsaOSS/golic@v0.2.0
go install github.com/AbsaOSS/golic@v0.3.0
golic inject -c="2021 MyCompany ltd."
```

Expand Down
2 changes: 1 addition & 1 deletion config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ golic:
prefix: "#"
.yml:
prefix: "#"
Dockerfile:
Dockerfile*:
prefix: "#"
Makefile:
prefix: "#"
Expand Down
20 changes: 18 additions & 2 deletions impl/inject/inject.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,29 @@ func headerContains(header string, values []string) bool{
return false
}

func getCommentedLicense(config *Config, o Options, rule string) (string, error) {
func matchRule(config *Config, fileName string) (rule string, ok bool) {
if _, ok = config.Golic.Rules[fileName]; ok {
return fileName, ok
}
// if rule is pattern like Dockerfile*
for k := range config.Golic.Rules {
matched, _ := filepath.Match(k, fileName)
if matched {
return k, true
}
}
return
}

func getCommentedLicense(config *Config, o Options, file string) (string, error) {
var ok bool
var template string
var rule string
if template, ok = config.Golic.Licenses[o.Template]; !ok {
return "",fmt.Errorf("no license found for %s, check configuration (%s)",o.Template,o.ConfigURL)
}
if _, ok = config.Golic.Rules[rule]; !ok {
//if _, ok = config.Golic.Rules[rule]; !ok {
if rule, ok = matchRule(config, file); !ok {
return "",fmt.Errorf("no rule found for %s, check configuration (%s)", rule,o.ConfigURL)
}
template = strings.ReplaceAll(template,"{{copyright}}", o.Copyright)
Expand Down

0 comments on commit f7e2a79

Please sign in to comment.