1
2
3
4
5 package main
6
7 import "os"
8
9 var cmds = map[string]func(){}
10
11 func register(name string, f func()) {
12 if cmds[name] != nil {
13 panic("duplicate registration: " + name)
14 }
15 cmds[name] = f
16 }
17
18 func registerInit(name string, f func()) {
19 if len(os.Args) >= 2 && os.Args[1] == name {
20 f()
21 }
22 }
23
24 func main() {
25 if len(os.Args) < 2 {
26 println("usage: " + os.Args[0] + " name-of-test")
27 return
28 }
29 f := cmds[os.Args[1]]
30 if f == nil {
31 println("unknown function: " + os.Args[1])
32 return
33 }
34 f()
35 }
36
View as plain text