cmd/showimp: support ignoring directories.

This commit is contained in:
Kyle Isom 2018-04-24 09:42:54 -07:00
parent 9e1aed257b
commit b6b33e00c8
1 changed files with 18 additions and 0 deletions

View File

@ -67,6 +67,10 @@ func init() {
} }
func walkFile(path string, info os.FileInfo, err error) error { func walkFile(path string, info os.FileInfo, err error) error {
if ignores[path] {
return filepath.SkipDir
}
if !sourceRegexp.MatchString(path) { if !sourceRegexp.MatchString(path) {
return nil return nil
} }
@ -97,10 +101,24 @@ func walkFile(path string, info os.FileInfo, err error) error {
return nil return nil
} }
var ignores = map[string]bool{}
func main() { func main() {
var ignoreLine string
var noVendor bool
flag.StringVar(&ignoreLine, "i", "", "comma-separated list of directories to ignore")
flag.BoolVar(&noVendor, "nv", false, "ignore the vendor directory")
flag.BoolVar(&debug, "v", false, "log debugging information") flag.BoolVar(&debug, "v", false, "log debugging information")
flag.Parse() flag.Parse()
if noVendor {
ignores["vendor"] = true
}
for _, word := range strings.Split(ignoreLine, ",") {
ignores[strings.TrimSpace(word)] = true
}
err := filepath.Walk(".", walkFile) err := filepath.Walk(".", walkFile)
die.If(err) die.If(err)