-
Notifications
You must be signed in to change notification settings - Fork 30
/
main.go
74 lines (59 loc) · 2.58 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
71
72
73
74
package main
import (
"os"
"path/filepath"
"github.com/urfave/cli"
_ "github.com/DarthSim/godotenv/autoload"
)
const version = "1.1.0"
func main() {
var (
conf hivemindConfig
err error
)
app := cli.NewApp()
app.Name = "Hivemind"
app.HelpName = "hivemind"
app.Usage = "The mind to rule processes of your development environment"
app.Description = "Hivemind is a process manager for Procfile-based applications"
app.Author = "Sergey \"DarthSim\" Alexandrovich"
app.Email = "[email protected]"
app.Version = version
app.ArgsUsage = "[procfile] (Use '-' to read from stdin, Procfile path can be also set with $HIVEMIND_PROCFILE)"
app.HideHelp = true
app.Flags = []cli.Flag{
cli.StringFlag{Name: "title, w", EnvVar: "HIVEMIND_TITLE", Usage: "Specify a title of the application", Destination: &conf.Title},
cli.StringFlag{Name: "processes, l", EnvVar: "HIVEMIND_PROCESSES", Usage: "Specify process names to launch. Divide names with comma", Destination: &conf.ProcNames},
cli.IntFlag{Name: "port, p", EnvVar: "HIVEMIND_PORT,PORT", Usage: "specify a port to use as the base", Value: 5000, Destination: &conf.PortBase},
cli.IntFlag{Name: "port-step, P", EnvVar: "HIVEMIND_PORT_STEP", Usage: "specify a step to increase port number", Value: 100, Destination: &conf.PortStep},
cli.StringFlag{Name: "root, d", EnvVar: "HIVEMIND_ROOT", Usage: "specify a working directory of application. Default: directory containing the Procfile", Destination: &conf.Root},
cli.IntFlag{Name: "timeout, t", EnvVar: "HIVEMIND_TIMEOUT", Usage: "specify the amount of time (in seconds) processes have to shut down gracefully before being brutally killed", Value: 5, Destination: &conf.Timeout},
cli.BoolFlag{Name: "no-prefix", EnvVar: "HIVEMIND_NO_PREFIX", Usage: "process names will not be printed if the flag is specified", Destination: &conf.NoPrefix},
cli.BoolFlag{Name: "print-timestamps, T", EnvVar: "HIVEMIND_PRINT_TIMESTAMPS", Usage: "timestamps will be printed if the flag is specified", Destination: &conf.PrintTimestamps},
}
app.Action = func(c *cli.Context) error {
switch c.NArg() {
case 0:
if path := os.Getenv("HIVEMIND_PROCFILE"); len(path) > 0 {
conf.Procfile = path
} else {
conf.Procfile = "./Procfile"
}
case 1:
conf.Procfile = c.Args().First()
default:
fatal("Specify a single procfile")
}
if conf.Timeout < 1 {
fatal("Timeout should be greater than 0")
}
if len(conf.Root) == 0 {
conf.Root = filepath.Dir(conf.Procfile)
}
conf.Root, err = filepath.Abs(conf.Root)
fatalOnErr(err)
newHivemind(conf).Run()
return nil
}
app.Run(os.Args)
}