forked from Cepave/open-falcon-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
81 lines (72 loc) · 1.79 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
package main
import (
"fmt"
"github.com/Cepave/open-falcon-backend/commands/reload"
"github.com/Cepave/open-falcon-backend/commands/restart"
"github.com/Cepave/open-falcon-backend/commands/start"
"github.com/Cepave/open-falcon-backend/commands/status"
"github.com/Cepave/open-falcon-backend/commands/stop"
"github.com/Cepave/open-falcon-backend/commands/tail"
"github.com/mitchellh/cli"
"io/ioutil"
"log"
"os"
)
// Commands is the mapping of all the available Consul commands.
var Commands map[string]cli.CommandFactory
var startCommand cli.Command
func init() {
//ui := &cli.BasicUi{Writer: os.Stdout}
Commands = map[string]cli.CommandFactory{
"start": func() (cli.Command, error) {
return &start.Command{}, nil
},
"stop": func() (cli.Command, error) {
return &stop.Command{}, nil
},
"restart": func() (cli.Command, error) {
return &restart.Command{}, nil
},
"status": func() (cli.Command, error) {
return &status.Command{}, nil
},
"tail": func() (cli.Command, error) {
return &tail.Command{}, nil
},
"reload": func() (cli.Command, error) {
return &reload.Command{}, nil
},
}
}
func main() {
os.Exit(realMain())
}
func realMain() int {
log.SetOutput(ioutil.Discard)
// Get the command line args. We shortcut "--version" and "-v" to
// just show the version.
args := os.Args[1:]
for _, arg := range args {
if arg == "--" {
break
}
if arg == "-v" || arg == "--version" {
newArgs := make([]string, len(args)+1)
newArgs[0] = "version"
copy(newArgs[1:], args)
args = newArgs
break
}
}
cli := &cli.CLI{
Args: args,
Commands: Commands,
// HelpFunc: cli.BasicHelpFunc("consul"),
}
exitCode, err := cli.Run()
if err != nil {
fmt.Fprintf(os.Stderr, "Error executing CLI: %s\n", err.Error())
return 1
}
return exitCode
}