/
main.go
62 lines (52 loc) · 1.26 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
package main
import (
"flag"
"fmt"
"os"
"runtime"
"strings"
)
var arguments struct {
runInDaemonMode bool
}
func parseArgs() {
//flag.StringVar(&arguments.configFile, "configfile", "", "set config file path")
flag.BoolVar(&arguments.runInDaemonMode, "d", false, "run in daemon mode")
flag.Parse()
}
func main() {
parseArgs()
args := flag.Args()
showMsg("arguments: %s", strings.Join(args, " "))
detectGoWorldPath()
if len(args) == 0 {
showMsg("no command to execute")
flag.Usage()
fmt.Fprintf(os.Stderr, "\tgoworld <build|start|stop|kill|reload|status> [server-id]\n")
os.Exit(1)
}
cmd := args[0]
if cmd == "build" || cmd == "start" || cmd == "stop" || cmd == "reload" || cmd == "kill" {
if len(args) != 2 {
showMsgAndQuit("server id is not given")
}
}
if cmd == "build" {
build(ServerID(args[1]))
} else if cmd == "start" {
start(ServerID(args[1]))
} else if cmd == "stop" {
if runtime.GOOS == "windows" {
showMsgAndQuit("stop does not work on Windows, use kill instead (will lose player data)")
}
stop(ServerID(args[1]))
} else if cmd == "reload" {
reload(ServerID(args[1]))
} else if cmd == "kill" {
kill(ServerID(args[1]))
} else if cmd == "status" {
status()
} else {
showMsgAndQuit("unknown command: %s", cmd)
}
}