-
Notifications
You must be signed in to change notification settings - Fork 6
/
main.go
69 lines (60 loc) · 1.78 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
package main
import (
cmd_beanstalkd "github.com/1xyz/coolbeans/beanstalkd/cmd"
cmd_cluster "github.com/1xyz/coolbeans/cluster/cmd"
"github.com/1xyz/coolbeans/tools"
"github.com/docopt/docopt-go"
log "github.com/sirupsen/logrus"
"os"
)
const version = "0.1.alpha"
func init() {
log.SetFormatter(&log.TextFormatter{})
log.SetOutput(os.Stdout)
log.SetLevel(log.InfoLevel)
}
func main() {
usage := `usage: coolbeans [--version] [(--verbose|--quiet)] [--help]
<command> [<args>...]
options:
-h, --help
--verbose Change the logging level verbosity
The commands are:
cluster-node Run a cluster node server
beanstalkd Run a beanstalkd proxy server
cluster-client Run the cluster's CLI client
See 'coolbeans <command> --help' for more information on a specific command.
`
parser := &docopt.Parser{OptionsFirst: true}
args, err := parser.ParseArgs(usage, nil, version)
if err != nil {
log.Errorf("error = %v", err)
os.Exit(1)
}
cmd := args["<command>"].(string)
cmdArgs := args["<args>"].([]string)
log.Debugf("global arguments: %v", args)
log.Debugf("command arguments: %v %v", cmd, cmdArgs)
verbose := tools.OptsBool(args, "--verbose")
quiet := tools.OptsBool(args, "--quiet")
if verbose == true {
log.SetLevel(log.DebugLevel)
} else if quiet == true {
log.SetLevel(log.WarnLevel)
}
RunCommand(cmd, cmdArgs, version)
log.Infof("done")
}
func RunCommand(c string, args []string, version string) {
argv := append([]string{c}, args...)
switch c {
case "cluster-node":
cmd_cluster.CmdClusterNode(argv, version)
case "beanstalkd":
cmd_beanstalkd.CmdBeanstalkd(argv, version)
case "cluster-client":
cmd_cluster.CmdClusterClient(argv, version)
default:
log.Fatalf("RunCommand: %s is not a supported command. See 'coolbeans help'", c)
}
}