-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptions.go
62 lines (52 loc) · 1.43 KB
/
options.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
package main
import (
"fmt"
"os"
// TODO: write custom implementation
"github.com/akamensky/argparse"
)
// options holds user-specified information about how to carry out the current
// operation.
var options struct {
pidfile string
cell string
cellName string
}
// parseArgs parses command line arguments for the cell.
func parseArgs() {
parser := argparse.NewParser("", "HLHV cell controller")
startCommand := parser.NewCommand("start", "Start a cell")
stopCommand := parser.NewCommand("stop", "Stop a cell")
restartCommand := parser.NewCommand("restart", "Restart a cell")
statusCommand := parser.NewCommand("status", "Display cell status")
pidfile := parser.String("p", "pidfile", &argparse.Options{
Required: false,
Help: "Specify the location the pidfile. Defaults to a " +
"file named hlhv-<cell name>.pid located at /run/",
})
cell := parser.String("c", "cell", &argparse.Options{
Required: false,
Default: "queen",
Help: "The cell to control",
})
err := parser.Parse(os.Args)
if err != nil {
fmt.Print(parser.Usage(err))
os.Exit(1)
}
options.pidfile = *pidfile
options.cellName = *cell
options.cell = "hlhv-" + *cell
if options.pidfile == "" {
options.pidfile = "/run/" + options.cell + ".pid"
}
if startCommand.Happened() {
doStart()
} else if stopCommand.Happened() {
doStop()
} else if restartCommand.Happened() {
doRestart()
} else if statusCommand.Happened() {
doStatus()
}
}