-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathslf.go
39 lines (32 loc) · 868 Bytes
/
slf.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
package main
import (
"flag"
"fmt"
"os"
"runtime"
"github.com/jopohl/slf/src"
)
func main() {
flag.Usage = func() {
_, _ = fmt.Fprintf(flag.CommandLine.Output(), "Usage %s PATH\nArguments:\n", os.Args[0])
flag.PrintDefaults()
}
numFiles := flag.Int("n", 10, "Number of entries to display. Must be a positive number.")
dirMode := flag.Bool("d", false, "Scan for directories instead of files.")
numThreads := flag.Int("x", runtime.NumCPU()+1, "Number of threads to use.")
flag.Parse()
if *numFiles <= 0 {
flag.PrintDefaults()
os.Exit(1)
}
pathsToScan := flag.Args()
if len(pathsToScan) < 1 {
pathsToScan = []string{"."}
}
for _, path := range pathsToScan {
tree := slf.ScanDirectoryTree(path, *numThreads)
entries := make([]*slf.Node, *numFiles)
slf.UpdateSizes(tree, &entries, *dirMode)
slf.PrintSizes(entries, *numFiles)
}
}