/
cli.go
140 lines (130 loc) · 2.98 KB
/
cli.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
package main
import (
"os"
"github.com/Sirupsen/logrus"
"github.com/codegangsta/cli"
)
var VERSION string = "dev"
var BUILD_DATE string = ""
func main() {
app := cli.NewApp()
app.Name = "stampzilla"
app.Version = VERSION + " (" + BUILD_DATE + ")"
app.Usage = "Manage stampzilla on the command line"
app.EnableBashCompletion = true
logrus.SetLevel(logrus.InfoLevel)
cliHandler := &cliHandler{}
app.Commands = []cli.Command{
{
Name: "start",
Usage: "start processes",
Action: addDebug(cliHandler.Start),
},
{
Name: "stop",
Usage: "start processes",
Action: addDebug(cliHandler.Stop),
},
{
Name: "restart",
ShortName: "r",
Usage: "restart processes",
Action: addDebug(cliHandler.Restart),
},
{
Name: "status",
ShortName: "st",
Usage: "show process status",
Action: addDebug(cliHandler.Status),
},
{
Name: "debug",
Usage: "Start one process and get stdout and stderr print on console.",
Action: addDebug(cliHandler.Debug),
},
{
Name: "log",
ShortName: "l",
Usage: "Open the log of the supplied process in less",
Action: addDebug(cliHandler.Log),
Flags: []cli.Flag{
cli.BoolFlag{
Name: "f",
Usage: "follow the log in real time",
},
},
},
{
Name: "list",
Usage: "Lists avilable releases",
Action: addDebug(cliHandler.List),
Flags: []cli.Flag{
cli.BoolFlag{
Name: "d",
Usage: "Show debug output",
},
},
},
{
Name: "install",
ShortName: "i",
Usage: "Downloads and installs all stampzilla nodes and the server from precompiled binaries",
Action: addDebug(cliHandler.Install),
Flags: []cli.Flag{
cli.BoolFlag{
Name: "u",
Usage: "Force update of existing binaries",
},
cli.BoolFlag{
Name: "d",
Usage: "Show debug output",
},
},
},
{
Name: "upgrade",
ShortName: "u",
Aliases: []string{"update"},
Usage: "Upgrades currently installed nodes and the server",
Action: addDebug(cliHandler.Upgrade),
Flags: []cli.Flag{
cli.BoolFlag{
Name: "d",
Usage: "Show debug output",
},
},
},
{
Name: "build",
ShortName: "b",
Usage: "Compile and install stampzilla nodes. If none is specified, all available nodes will be installed",
Action: addDebug(cliHandler.Build),
Flags: []cli.Flag{
cli.BoolFlag{
Name: "u",
Usage: "Force update of source files before compile",
},
cli.BoolFlag{
Name: "d",
Usage: "Show debug output",
},
},
},
{
Name: "updateconfig",
ShortName: "uc",
Usage: "Generates new /etc/stampzilla/nodes.conf merging new nodes with existing config",
Action: cliHandler.UpdateConfig,
},
}
app.Run(os.Args)
}
func addDebug(in func(c *cli.Context)) func(c *cli.Context) {
return func(c *cli.Context) {
if c.Bool("d") {
logrus.SetLevel(logrus.DebugLevel)
logrus.Info("Debug output activated")
}
in(c)
}
}