Skip to content

Commit

Permalink
file-match
Browse files Browse the repository at this point in the history
  • Loading branch information
kuritka committed Mar 18, 2021
1 parent b98896d commit f44c680
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ create `.licignore` in project root
Install and run **GOLIC**
```shell
# GO 1.16
go install github.com/AbsaOSS/[email protected].6
go install github.com/AbsaOSS/[email protected].7
golic inject -c="2021 MyCompany ltd."
```

Expand Down
2 changes: 1 addition & 1 deletion cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"github.com/spf13/cobra"
)

const version = "v0.4.6"
const version = "v0.4.7"

var versionCmd = &cobra.Command{
Use: "version",
Expand Down
11 changes: 9 additions & 2 deletions impl/inject/inject.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func inject(path string, o Options, config *Config) (err error, skip bool) {
if err != nil {
return err,false
}
rule := getRule(path)
rule := getRule(config, path)
license,err := getCommentedLicense(config, o, rule)
if err != nil {
return err, false
Expand Down Expand Up @@ -236,7 +236,14 @@ func splitSource(source string) (firstLine, rest string){
return "",source
}

func getRule(path string) (rule string) {
func getRule(config *Config, path string) (rule string) {
fileName := filepath.Base(path)
for k := range config.Golic.Rules {
matched, _ := filepath.Match(k, fileName)
if matched {
return k
}
}
rule = filepath.Ext(path)
if rule == "" {
rule = filepath.Base(path)
Expand Down

0 comments on commit f44c680

Please sign in to comment.