Skip to content

Commit

Permalink
Support multiple paths on the command line
Browse files Browse the repository at this point in the history
This way, you can run qloc across multiple directories.
  • Loading branch information
ascandella committed Jan 5, 2016
1 parent 4862494 commit 32aa8de
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ func ShouldExamine(ext string) bool {
func main() {
flag.Parse()

path := flag.Arg(0)
if path == "" {
path = "."
paths := flag.Args()
if len(paths) == 0 {
paths = []string{"."}
}

if *exts != "" {
Expand All @@ -47,7 +47,7 @@ func main() {

work := make(chan string, 100)
results := make(chan CountByExt, *procs)
go IterateDir(path, work)
go IterateDir(work, paths...)

for i := 0; i < *procs; i++ {
go FileWorker(work, results, &progress)
Expand Down Expand Up @@ -102,7 +102,7 @@ func FileWorker(files chan string, result chan CountByExt, progress *int64) {
}
}

func IterateDir(root string, work chan string) {
func IterateDir(work chan string, roots ...string) {
walk := func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
Expand Down Expand Up @@ -130,9 +130,11 @@ func IterateDir(root string, work chan string) {
return nil
}

err := filepath.Walk(root, walk)
if err != nil {
log.Println(err)
for _, root := range roots {
err := filepath.Walk(root, walk)
if err != nil {
log.Println(err)
}
}

close(work)
Expand Down

0 comments on commit 32aa8de

Please sign in to comment.