-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
63 lines (51 loc) · 1.01 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
58
59
60
61
62
63
package main
import (
"flag"
"fmt"
"os"
"bufio"
"io"
"progress/cmd/core"
"strings"
)
func main() {
flag.Parse()
if len(flag.Args()) < 2 {
fmt.Println("Too few args specified. Supported commands are 'times', 'unique' and 'hang'.")
os.Exit(1)
}
var p core.Progress
switch flag.Arg(0) {
case "times":
p = core.NewProgressTimings()
case "unique":
p = core.NewProgressUniques()
case "hang":
p = core.NewProgressHangs()
default:
fmt.Printf("Invalid command: '%s'. Supported commands are 'times', 'unique' and 'hang'.\n", flag.Arg(0))
os.Exit(1)
}
var line string
for i := 1; i < flag.NArg(); i++ {
fmt.Printf("-------- %s --------\n", flag.Arg(i))
progressFile, err := os.Open(flag.Arg(i))
if err != nil {
panic(err)
}
reader := bufio.NewReader(progressFile)
for {
line, err = reader.ReadString('\n')
line = strings.TrimSpace(line)
p.ProcessLine(line)
if err != nil {
break
}
}
if err != io.EOF {
panic(err)
}
progressFile.Close()
}
p.Results()
}