-
Notifications
You must be signed in to change notification settings - Fork 0
/
xfg_pre_walk.go
82 lines (69 loc) · 1.85 KB
/
xfg_pre_walk.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package main
import (
"github.com/bayashi/xfg/internal/xfgignore"
"github.com/bayashi/xfg/internal/xfgutil"
)
func (x *xfg) preWalkDir() error {
if x.options.IgnoreCase {
if err := x.prepareIgnoreCaseRe(); err != nil {
return err
}
if err := x.prepareIgnoreOption(); err != nil {
return err
}
}
if len(x.options.SearchPathRe) > 0 {
if searchPathRe, err := xfgutil.CompileRegexps(x.options.SearchPathRe, !x.options.NotWordBoundary); err != nil {
return err
} else {
x.extra.searchPathRe = searchPathRe
}
}
if len(x.options.SearchGrepRe) > 0 {
if searchGrepRe, err := xfgutil.CompileRegexps(x.options.SearchGrepRe, !x.options.NotWordBoundary); err != nil {
return err
} else {
x.extra.searchGrepRe = searchGrepRe
}
}
return nil
}
func (x *xfg) prepareIgnoreCaseRe() error {
if searchPathi, err := xfgutil.CompileRegexpsIgnoreCase(x.options.SearchPath); err != nil {
return err
} else {
x.extra.searchPathi = searchPathi
}
if len(x.options.SearchGrep) > 0 {
if searchGrepi, err := xfgutil.CompileRegexpsIgnoreCase(x.options.SearchGrep); err != nil {
return err
} else {
x.extra.searchGrepi = searchGrepi
}
}
return nil
}
func (x *xfg) prepareIgnoreOption() error {
if len(x.options.Ignore) > 0 {
if ignoreOptionRe, err := xfgutil.CompileRegexpsIgnoreCase(x.options.Ignore); err != nil {
return err
} else {
x.extra.ignoreOptionRe = ignoreOptionRe
}
}
return nil
}
func (x *xfg) initIgnoreMatchers(rootDir string) xfgignore.Matchers {
var gms xfgignore.Matchers
if !x.options.SkipGitIgnore {
if ms := xfgignore.SetUpGlobalGitIgnores(rootDir, x.cli.homeDir); len(ms) > 0 {
gms = append(gms, ms...)
}
}
if !x.options.SkipXfgIgnore {
if ms := xfgignore.SetupGlobalXFGIgnore(rootDir, x.cli.homeDir, x.options.XfgIgnoreFile); len(ms) > 0 {
gms = append(gms, ms...)
}
}
return gms
}