-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
62 lines (52 loc) · 1.14 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
package main
import (
"context"
"flag"
"fmt"
"os"
"runtime"
"runtime/pprof"
"github.com/TheGrizzlyDev/git-analyse/bisect"
_ "github.com/TheGrizzlyDev/git-analyse/settings"
)
var (
bisectCmd = flag.NewFlagSet("bisect", flag.ExitOnError)
jobs = bisectCmd.Int("jobs", runtime.NumCPU(), "how many jobs can you run concurrently")
goodRev = bisectCmd.String("good", "", "last known good revision")
badRev = bisectCmd.String("bad", "", "first known bad revision")
// internal
profiled = ""
)
type command interface {
Run(ctx context.Context) error
}
func main() {
if len(os.Args) < 2 {
fmt.Println("expected 'bisect' subcommand")
os.Exit(1)
}
var cmd command
switch os.Args[1] {
case "bisect":
bisectCmd.Parse(os.Args[2:])
cmd = bisect.NewBisect(bisect.BisectOpts{
Jobs: *jobs,
Good: *goodRev,
Bad: *badRev,
Cmd: bisectCmd.Args(),
})
}
if profiled != "" {
fmt.Printf("Profiling on %s\n", profiled)
f, err := os.Create(profiled)
if err != nil {
panic(err)
}
pprof.StartCPUProfile(f)
defer pprof.StopCPUProfile()
}
ctx := context.TODO()
if err := cmd.Run(ctx); err != nil {
panic(err)
}
}