-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.go
70 lines (59 loc) · 1.36 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
package main
import (
"flag"
"fmt"
"os"
"github.com/ramantehlan/mateix/packages/e"
)
func main() {
updateCmd := flag.NewFlagSet("update", flag.ExitOnError)
updateFilePtr := updateCmd.String("file", "", "File path which you wish to sync")
serverCmd := flag.NewFlagSet("server", flag.ExitOnError)
serverCmd.Bool("start", true, "Start the mateix server")
serverCmd.Bool("stop", false, "stop the mateix server")
// No sub-command
if len(os.Args) < 2 {
e.Error("Sub command required")
os.Exit(1)
}
// Choose which sub-command
switch os.Args[1] {
case "update":
updateCmd.Parse(os.Args[2:])
// Update sub-command
if updateCmd.Parsed() {
if *updateFilePtr == "" {
fmt.Println("usage of update:")
updateCmd.PrintDefaults()
os.Exit(1)
}
Update(*updateFilePtr)
}
case "init":
Initialize()
case "uninstall":
Uninstall()
case "server":
serverCmd.Parse(os.Args[2:])
if serverCmd.Parsed() && len(os.Args[0:]) <= 3 {
arg := os.Args[2]
if arg == "--start" || arg == "-start" {
server(true)
} else if arg == "--stop" || arg == "-stop" {
server(false)
} else {
fmt.Println("usage of server:")
serverCmd.PrintDefaults()
os.Exit(1)
}
} else {
fmt.Println("usage of server:")
serverCmd.PrintDefaults()
os.Exit(1)
}
default:
e.Error("Unknown sub command")
flag.PrintDefaults()
os.Exit(1)
}
}