-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.go
99 lines (94 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package main
import (
"fmt"
"os"
)
import (
"github.com/timtadh/getopt"
)
import (
"github.com/timtadh/dynagrok/cmd"
"github.com/timtadh/dynagrok/grok"
"github.com/timtadh/dynagrok/instrument"
"github.com/timtadh/dynagrok/localize"
"github.com/timtadh/dynagrok/mutate"
"github.com/timtadh/dynagrok/objectstate"
)
func main() {
fmt.Fprintln(os.Stderr, os.Args)
var config cmd.Config
var cleanup func()
main := NewMain(&config, &cleanup)
grk := grok.NewCommand(&config)
inst := instrument.NewCommand(&config)
mut := mutate.NewCommand(&config)
loc := localize.NewCommand(&config)
obj := objectstate.NewCommand(&config)
cmd.Main(cmd.Concat(
main,
cmd.Commands(map[string]cmd.Runnable{
grk.Name(): grk,
inst.Name(): inst,
mut.Name(): mut,
loc.Name(): loc,
obj.Name(): obj,
}),
), &cleanup)
}
func NewMain(c *cmd.Config, cleanup *func()) cmd.Runnable {
return cmd.Cmd(os.Args[0],
`[options] <pkg>`,
`
Option Flags
-h,--help Show this message
-p,--cpu-profile=<path> Path to write the cpu-profile
-r,--go-root=<path> go root
-g,--go-path=<path> go path
-d,--dynagrok-path=<path> dynagrok path
`,
"p:r:g:d:",
[]string{
"cpu-profile=",
"go-root=",
"go-path=",
"dynagrok-path=",
},
func(r cmd.Runnable, args []string, optargs []getopt.OptArg) ([]string, *cmd.Error) {
GOROOT := os.Getenv("GOROOT")
GOPATH := os.Getenv("GOPATH")
DGPATH := os.Getenv("DGPATH")
cpuProfile := ""
for _, oa := range optargs {
switch oa.Opt() {
case "-p", "--cpu-profile":
cpuProfile = oa.Arg()
case "-g", "--go-path":
GOPATH = oa.Arg()
case "-d", "--dynagrok-path":
DGPATH = oa.Arg()
case "-r", "--go-root":
GOROOT = oa.Arg()
}
}
if cpuProfile != "" {
cleanup, err := cmd.CPUProfile(cpuProfile)
if err != nil {
return nil, err
}
defer cleanup()
}
if cpuProfile != "" {
clean, err := cmd.CPUProfile(cpuProfile)
if err != nil {
return nil, err
}
*cleanup = clean
}
*c = cmd.Config{
GOROOT: GOROOT,
GOPATH: GOPATH,
DGPATH: DGPATH,
}
return args, nil
})
}