forked from remind101/empire
-
Notifications
You must be signed in to change notification settings - Fork 0
/
create.go
76 lines (61 loc) · 1.69 KB
/
create.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
package main
import (
"log"
"github.com/remind101/empire/pkg/heroku"
)
var cmdCreate = &Command{
Run: maybeMessage(runCreate),
Usage: "create [-r <region>] [-o <org>] [--http-git] [<name>]",
OptionalMessage: true,
Category: "app",
Short: "create an app",
Long: `
Create creates a new Heroku app. If <name> is not specified, the
app is created with a random haiku name.
Options:
-r <region> Heroku region to create app in
-o <org> name of Heroku organization to create app in
<name> optional name for the app
Examples:
$ emp create
Created dodging-samurai-42.
$ emp create -r eu myapp
Created myapp.
`,
}
var flagRegion string
var flagOrgName string
var flagHTTPGit bool
func init() {
cmdCreate.Flag.StringVarP(&flagRegion, "region", "r", "", "region name")
cmdCreate.Flag.StringVarP(&flagOrgName, "org", "o", "", "organization name")
cmdCreate.Flag.BoolVar(&flagHTTPGit, "http-git", false, "use http git remote")
}
func runCreate(cmd *Command, args []string) {
appname := ""
if len(args) > 0 {
appname = args[0]
}
message := getMessage()
var opts heroku.OrganizationAppCreateOpts
if appname != "" {
opts.Name = &appname
}
if flagOrgName == "personal" { // "personal" means "no org"
personal := true
opts.Personal = &personal
} else if flagOrgName != "" {
opts.Organization = &flagOrgName
}
if flagRegion != "" {
opts.Region = &flagRegion
}
app, err := client.OrganizationAppCreate(&opts, message)
must(err)
addGitRemote(app, flagHTTPGit)
if app.Organization != nil {
log.Printf("Created %s in the %s org.", app.Name, app.Organization.Name)
} else {
log.Printf("Created %s.", app.Name)
}
}