forked from linfn/camo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
54 lines (44 loc) · 744 Bytes
/
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
package main // import "github.com/linfn/camo"
import (
"fmt"
"os"
"github.com/linfn/camo/pkg/cmd"
)
var (
buildCommit string
buildDate string
)
var help cmd.Help
var commands = []cmd.Command{
&cmd.Client{},
&cmd.Server{},
&cmd.Version{
BuildCommit: buildCommit,
BuildDate: buildDate,
},
&help,
}
func getCommand(name string) (cmd.Command, bool) {
for _, c := range commands {
if c.Name() == name {
return c, true
}
}
return nil, false
}
func init() {
help.Commands = commands
}
func main() {
if len(os.Args) < 2 {
help, _ := getCommand("help")
help.Run()
return
}
cmd, ok := getCommand(os.Args[1])
if !ok {
fmt.Fprintln(os.Stderr, "unknow command")
os.Exit(1)
}
cmd.Run(os.Args[2:]...)
}