/
main.go
76 lines (64 loc) · 2.17 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
64
65
66
67
68
69
70
71
72
73
74
75
76
package main
import (
"context"
"flag"
"log"
"os"
"runtime/pprof"
"github.com/google/subcommands"
"github.com/nelhage/taktician/cmd/internal/analyze"
"github.com/nelhage/taktician/cmd/internal/canonicalize"
"github.com/nelhage/taktician/cmd/internal/gencorpus"
"github.com/nelhage/taktician/cmd/internal/genopenings"
"github.com/nelhage/taktician/cmd/internal/importptn"
"github.com/nelhage/taktician/cmd/internal/openings"
"github.com/nelhage/taktician/cmd/internal/play"
"github.com/nelhage/taktician/cmd/internal/playtak"
"github.com/nelhage/taktician/cmd/internal/selfplay"
"github.com/nelhage/taktician/cmd/internal/serve"
"github.com/nelhage/taktician/cmd/internal/tei"
)
func innerMain() int {
subcommands.Register(subcommands.HelpCommand(), "")
subcommands.Register(subcommands.FlagsCommand(), "")
// subcommands.Register(subcommands.CommandsCommand(), "")
subcommands.Register(&analyze.Command{}, "")
subcommands.Register(&selfplay.Command{}, "")
subcommands.Register(&playtak.Command{}, "")
subcommands.Register(&serve.Command{}, "")
subcommands.Register(&play.Command{}, "")
subcommands.Register(&tei.Command{}, "")
subcommands.Register(&genopenings.Command{}, "")
subcommands.Register(&openings.Command{}, "")
subcommands.Register(&canonicalize.Command{}, "")
subcommands.Register(&gencorpus.Command{}, "")
subcommands.Register(&importptn.Command{}, "")
var cpuProfile, memProfile string
flag.StringVar(&cpuProfile, "cpuprofile", "", "write CPU profile")
flag.StringVar(&memProfile, "memprofile", "", "write memory profile")
flag.Parse()
if cpuProfile != "" {
f, e := os.OpenFile(cpuProfile, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
if e != nil {
log.Fatalf("open cpu-profile: %s: %v", cpuProfile, e)
}
pprof.StartCPUProfile(f)
defer f.Close()
defer pprof.StopCPUProfile()
}
if memProfile != "" {
f, e := os.OpenFile(memProfile, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
if e != nil {
log.Fatalf("open memory profile: %s: %v", cpuProfile, e)
}
defer func() {
pprof.Lookup("allocs").WriteTo(f, 0)
f.Close()
}()
}
ctx := context.Background()
return int(subcommands.Execute(ctx))
}
func main() {
os.Exit(innerMain())
}