-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
66 lines (53 loc) · 1.77 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
package main // import "github.com/TaserudConsulting/goprocmgr"
import (
"flag"
"fmt"
)
func main() {
var config Config
var configFile string
var addFlag string
var listFlag bool
var listFormat string
var versionFlag bool
var serveFlag bool
var removeFlag string
var startFlag string
var stopFlag string
var logsFlag string
flag.StringVar(&configFile, "config", config.GuessFileName(""), "Specify config file")
flag.BoolVar(&serveFlag, "serve", true, "Run the serve command (start the web server)")
flag.BoolVar(&listFlag, "list", false, "List the stored servers")
flag.StringVar(&listFormat, "list-format", "table", "List format (table, csv) when using the list command")
flag.BoolVar(&versionFlag, "version", false, "Print the version")
flag.StringVar(&addFlag, "add", "", "Add a new server, will capture the current directory and environment and then takes the command as an argument")
flag.StringVar(&removeFlag, "remove", "", "Remove an existing server by it's name")
flag.StringVar(&startFlag, "start", "", "Start an existing server by it's name")
flag.StringVar(&stopFlag, "stop", "", "Stop an existing server by it's name")
flag.StringVar(&logsFlag, "logs", "", "Tail the logs from an existing server by it's name")
flag.Parse()
if versionFlag {
fmt.Println("goprocmgr version %undefined-version%")
return
}
runner := Runner{config: &config}
serve := NewServe(&config, &runner)
cli := Cli{config: &config}
config.Read(configFile)
switch true {
case listFlag:
cli.List(listFormat)
case len(addFlag) > 0:
cli.Add(addFlag)
case len(removeFlag) > 0:
cli.Remove(removeFlag)
case len(startFlag) > 0:
cli.Start(startFlag)
case len(stopFlag) > 0:
cli.Stop(stopFlag)
case len(logsFlag) > 0:
cli.Logs(logsFlag)
case serveFlag:
serve.Run()
}
}