Skip to content

Commit

Permalink
added py-pip + more info on dryrun (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
tg44 committed Dec 31, 2021
1 parent 05a06c2 commit 20586ee
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 7 deletions.
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ func main() {
Action: func(c *cli.Context) error {
if dry {
res := pkg.GetExcludedPaths(rulePath, par, buffer, verbose)
fmt.Println("-----")
fmt.Print(strings.Join(res,"\r\n"))
fmt.Print("\n")
} else {
Expand Down
8 changes: 3 additions & 5 deletions pkg/parser/file-trigger.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ type FileTriggerSettings struct {
ExcludePaths []string
}

const FileTriggerType = ""

func fileTriggerSettingsParse(i map[string]interface{}) (*FileTriggerSettings, error) {
fileTrigger, found1 := i["fileTrigger"].(string)
excludePathsI, found2 := i["excludePaths"].([]interface{})
Expand All @@ -37,14 +35,14 @@ func fileTriggerWalker(rule Rule, settings FileTriggerSettings) walker.Walker {
fixIgnorePaths = append(fixIgnorePaths, path)
}
}
return func(path string, subfiles []os.FileInfo) ([]string, []string, []string) {
return func(path string, subfiles []os.FileInfo) ([]string, []string, []string, string) {
if utils.ContainsFIA(subfiles, settings.FileTrigger) {
var ret []string
for _, f := range settings.ExcludePaths {
ret = append(ret, filepath.Join(path, f))
}
return ret, []string{}, fixIgnorePaths
return ret, []string{}, fixIgnorePaths, rule.Name
}
return []string{}, []string{}, fixIgnorePaths
return []string{}, []string{}, fixIgnorePaths, rule.Name
}
}
21 changes: 19 additions & 2 deletions pkg/walker/walker.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import (
//first ret is the excluding paths we found
//second ret is the global ignore paths if we don't want other runners to go into it
//third ret is the local ignore path if we don't want to go into it next time
type Walker = func(path string, files []os.FileInfo) ([]string, []string, []string)
//last param is the name of the rule for verbose
type Walker = func(path string, files []os.FileInfo) ([]string, []string, []string, string)

type WalkerIgnores struct {
w Walker
Expand Down Expand Up @@ -94,7 +95,23 @@ func walk(runnerId int, rootpath string, walkers []Walker, alreadyFiltered []str
ignores := []WalkerIgnores{}
globalIgnores := []string{}
for _, walker := range walkers {
r, i1, i2 := walker(l.Data, files)
r, i1, i2, name := walker(l.Data, files)
if(verbose && len(r) > 0) {
fmt.Println("-----")
fmt.Println(name)
fmt.Println(l.Data)
for _, v := range r {
fmt.Println("\t", v)
}
fmt.Println("-")
for _, v := range i1 {
fmt.Println("\t", v)
}
fmt.Println("-")
for _, v := range i2 {
fmt.Println("\t", v)
}
}
res = res.Prepend(r)
ignores = append(ignores, WalkerIgnores{walker, i2})
globalIgnores = append(globalIgnores, i1...)
Expand Down
10 changes: 10 additions & 0 deletions rules/python-pip.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: "python-pip"
enabled: true
searchPaths: ["~"]
ignorePaths: []
ruleType: "file-trigger"
ruleSettings:
fileTrigger: "Pipfile"
excludePaths:
- ".venv"
- "venv"

0 comments on commit 20586ee

Please sign in to comment.