-
Notifications
You must be signed in to change notification settings - Fork 7
/
create.go
74 lines (59 loc) · 1.63 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
package main
import (
"log"
"github.com/remind101/emp/Godeps/_workspace/src/github.com/remind101/empire/pkg/heroku"
)
var cmdCreate = &Command{
Run: runCreate,
Usage: "create [-r <region>] [-o <org>] [--http-git] [<name>]",
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]
}
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)
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)
}
}