-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
59 lines (55 loc) · 908 Bytes
/
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
package main
import (
"fmt"
"os"
"path/filepath"
"strconv"
"xonotic-map-repo/conv"
"xonotic-map-repo/serve"
"xonotic-map-repo/utils"
)
var FailIf = utils.FailIf
var AnyString = utils.AnyString
func usage() {
name := filepath.Base(os.Args[0])
fmt.Printf("Usage:\n %s conv [maps.json]\n %s serve [port]\n", name, name)
os.Exit(0)
}
func main() {
argv := os.Args
argc := len(argv)
var (
command string
path string
port int
err error
)
if argc == 1 {
usage()
}
if command = argv[1]; !AnyString(command, "conv", "serve") {
usage()
}
if argc == 2 {
switch command {
case "conv":
path = "maps.json"
case "serve":
port = 8080
}
} else {
switch command {
case "conv":
path = argv[2]
case "serve":
port, err = strconv.Atoi(argv[2])
FailIf(err)
}
}
switch command {
case "conv":
conv.Conv(path)
case "serve":
serve.Serve(port)
}
}