forked from helmfile/chartify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch.go
41 lines (35 loc) · 745 Bytes
/
search.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package chartify
import (
"os"
"strings"
)
type SearchFileOpts struct {
basePath string
matchSubPath string
fileType []string
}
// SearchFiles returns a slice of files that are within the base path, has a matching sub path and file type
func (r *Runner) SearchFiles(o SearchFileOpts) ([]string, error) {
var files []string
err := r.Walk(o.basePath, func(path string, info os.FileInfo, err error) error {
if !strings.Contains(path, o.matchSubPath+"/") {
return nil
}
var any bool
for _, t := range o.fileType {
any = strings.HasSuffix(path, t)
if any {
break
}
}
if !any {
return nil
}
files = append(files, path)
return nil
})
if err != nil {
return nil, err
}
return files, nil
}