forked from stelligent/mu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.go
99 lines (85 loc) · 1.99 KB
/
app.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package cli
import (
"github.com/stelligent/mu/common"
"github.com/stelligent/mu/provider/aws"
"github.com/urfave/cli"
"io/ioutil"
"os"
)
// NewApp creates a new CLI app
func NewApp() *cli.App {
context := common.NewContext()
app := cli.NewApp()
app.Name = "mu"
app.Usage = "Microservice Platform on AWS"
app.Version = common.GetVersion()
app.EnableBashCompletion = true
app.Commands = []cli.Command{
*newInitCommand(context),
*newEnvironmentsCommand(context),
*newServicesCommand(context),
*newPipelinesCommand(context),
*newDatabasesCommand(context),
}
app.Before = func(c *cli.Context) error {
// setup logging
if c.Bool("verbose") {
common.SetupLogging(2)
} else if c.Bool("silent") {
common.SetupLogging(0)
} else {
common.SetupLogging(1)
}
// initialize context
err := context.InitializeContext()
if err != nil {
return err
}
// TODO: support initializing context from other cloud providers?
err = aws.InitializeContext(context, c.String("profile"), c.String("region"), c.Bool("dryrun"))
if err != nil {
return err
}
if c.Bool("silent") {
context.DockerOut = ioutil.Discard
} else {
context.DockerOut = os.Stdout
}
err = context.InitializeConfigFromFile(c.String("config"))
if err != nil {
// ignore errors for init command
if c.Args().First() != "init" {
log.Warningf("Unable to load mu config: %v", err)
}
}
return nil
}
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "config, c",
Usage: "path to config file",
Value: "mu.yml",
},
cli.StringFlag{
Name: "region, r",
Usage: "AWS Region to use",
},
cli.StringFlag{
Name: "profile, p",
Usage: "AWS config profile to use",
},
cli.BoolFlag{
Name: "silent, s",
Usage: "silent mode, errors only",
},
cli.BoolFlag{
Name: "verbose, V",
Usage: "increase level of log verbosity",
},
cli.BoolFlag{
Name: "dryrun, d",
Usage: "generate the cloudformation templates without upserting stacks",
},
}
return app
}