forked from imjerrybao/apex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.go
60 lines (45 loc) · 1.07 KB
/
init.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
// Package init bootstraps an Apex project.
package init
import (
"errors"
"github.com/aws/aws-sdk-go/service/iam"
"github.com/tj/cobra"
"github.com/apex/apex/boot"
"github.com/apex/apex/cmd/apex/root"
"github.com/apex/apex/stats"
)
var credentialsError = `
AWS region missing, are your credentials set up? Try:
$ export AWS_PROFILE=myapp-stage
$ apex init
Visit http://apex.run/#aws-credentials for more details on
setting up AWS credentials and specifying which profile to
use.
`
// Command config.
var Command = &cobra.Command{
Use: "init",
Short: "Initialize a project",
PersistentPreRun: root.PreRunNoop,
RunE: run,
}
// Initialize.
func init() {
root.Register(Command)
}
// Run command.
func run(c *cobra.Command, args []string) error {
stats.Track("Init", nil)
if err := root.Prepare(c, args); err != nil {
return err
}
region := root.Config.Region
if region == nil {
return errors.New(credentialsError)
}
b := boot.Bootstrapper{
IAM: iam.New(root.Session),
Region: *region,
}
return b.Boot()
}