-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
57 lines (49 loc) · 1.2 KB
/
main.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
package main
import (
"flag"
"fmt"
"io"
"log"
"os"
)
type progOptions struct {
debug bool
printYaml bool
tsvPath string
}
func main() {
conf := progOptions{}
flag.BoolVar(&conf.debug, "debug", false, "Whether to print debug logs.")
flag.StringVar(&conf.tsvPath, "tsv", "", "Path of a tsv file to write detailed results. No effect if not provided. Use '-' to print to stdout.")
flag.BoolVar(&conf.printYaml, "yaml", false, "Whether to print global stats in yaml like syntax instead of pretty table.")
flag.Parse()
paths := flag.Args()
if len(paths) == 0 {
fmt.Printf("USAGE: %s [-debug][-tsv TSVPATH] PATH [...]\n", os.Args[0])
os.Exit(1)
}
if !conf.debug {
log.SetOutput(io.Discard) // disable logging
}
gst := NewGlobalStats(paths)
gst.InspectBatch()
if conf.printYaml {
gst.PrintGlobalStats()
} else {
gst.PrintGlobalStatsPretty()
}
switch conf.tsvPath {
case "": // do nothing
case "-":
gst.DumpStatDetailsAsTsv(os.Stdout)
default:
f, err := os.Create(conf.tsvPath)
if err != nil {
fmt.Println("Could not write tsv file:", err.Error())
os.Exit(2)
}
defer f.Close()
gst.DumpStatDetailsAsTsv(f)
fmt.Println("Detailed results written to", conf.tsvPath)
}
}