From b6b33e00c8ae53963677d36f712dc5376319a986 Mon Sep 17 00:00:00 2001 From: Kyle Isom Date: Tue, 24 Apr 2018 09:42:54 -0700 Subject: [PATCH] cmd/showimp: support ignoring directories. --- cmd/showimp/main.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/cmd/showimp/main.go b/cmd/showimp/main.go index a8d291e..708928c 100644 --- a/cmd/showimp/main.go +++ b/cmd/showimp/main.go @@ -67,6 +67,10 @@ func init() { } func walkFile(path string, info os.FileInfo, err error) error { + if ignores[path] { + return filepath.SkipDir + } + if !sourceRegexp.MatchString(path) { return nil } @@ -97,10 +101,24 @@ func walkFile(path string, info os.FileInfo, err error) error { return nil } +var ignores = map[string]bool{} + 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.Parse() + if noVendor { + ignores["vendor"] = true + } + + for _, word := range strings.Split(ignoreLine, ",") { + ignores[strings.TrimSpace(word)] = true + } + err := filepath.Walk(".", walkFile) die.If(err)