forked from vincepri/orchestra
-
Notifications
You must be signed in to change notification settings - Fork 11
/
main.go
74 lines (67 loc) · 1.78 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 (
"fmt"
"os"
"path"
"path/filepath"
log "github.com/cihub/seelog"
"github.com/codegangsta/cli"
"github.com/monzo/orchestra/commands"
"github.com/monzo/orchestra/config"
"github.com/monzo/orchestra/services"
)
var app *cli.App
const defaultConfigFile = "orchestra.yml"
func main() {
defer log.Flush()
app = cli.NewApp()
app.Name = "Orchestra"
app.Usage = "Orchestrate Go Services"
app.EnableBashCompletion = true
app.Commands = []cli.Command{
*commands.BuildCommand,
*commands.ExportCommand,
*commands.InstallCommand,
*commands.LogsCommand,
*commands.PsCommand,
*commands.RestartCommand,
*commands.StartCommand,
*commands.StopCommand,
*commands.TestCommand,
}
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "config, c",
Value: "orchestra.yml",
Usage: "Specify a different config file to use",
EnvVar: "ORCHESTRA_CONFIG",
},
}
// init checks for an existing orchestra.yml in the current working directory
// and creates a new .orchestra directory (if doesn't exist)
app.Before = func(c *cli.Context) error {
confVal := c.GlobalString("config")
if confVal == "" {
confVal = defaultConfigFile
}
config.ConfigPath, _ = filepath.Abs(confVal)
if _, err := os.Stat(config.ConfigPath); os.IsNotExist(err) {
fmt.Printf("No %s found. Have you specified the right directory?\n", c.GlobalString("config"))
os.Exit(1)
}
services.ProjectPath, _ = path.Split(config.ConfigPath)
services.OrchestraServicePath = services.ProjectPath + ".orchestra"
if err := os.Mkdir(services.OrchestraServicePath, 0766); err != nil && os.IsNotExist(err) {
fmt.Println(err.Error())
os.Exit(1)
}
config.ParseGlobalConfig()
services.Init()
return nil
}
app.Version = "0.1"
app.Run(os.Args)
if commands.HasErrors() {
os.Exit(1)
}
}