forked from cloudfoundry/cli
/
create_app_command.go
57 lines (48 loc) · 1.62 KB
/
create_app_command.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
package v7
import (
"code.cloudfoundry.org/cli/api/cloudcontroller/ccerror"
"code.cloudfoundry.org/cli/api/cloudcontroller/ccv3/constant"
"code.cloudfoundry.org/cli/command/flag"
"code.cloudfoundry.org/cli/resources"
)
type CreateAppCommand struct {
BaseCommand
RequiredArgs flag.AppName `positional-args:"yes"`
AppType flag.AppType `long:"app-type" choice:"buildpack" choice:"docker" description:"App lifecycle type to stage and run the app" default:"buildpack"`
usage interface{} `usage:"CF_NAME create-app APP_NAME [--app-type (buildpack | docker)]"`
relatedCommands interface{} `related_commands:"app, apps, push"`
}
func (cmd CreateAppCommand) Execute(args []string) error {
err := cmd.SharedActor.CheckTarget(true, true)
if err != nil {
return err
}
user, err := cmd.Config.CurrentUser()
if err != nil {
return err
}
cmd.UI.DisplayTextWithFlavor("Creating app {{.AppName}} in org {{.CurrentOrg}} / space {{.CurrentSpace}} as {{.CurrentUser}}...", map[string]interface{}{
"AppName": cmd.RequiredArgs.AppName,
"CurrentSpace": cmd.Config.TargetedSpace().Name,
"CurrentOrg": cmd.Config.TargetedOrganization().Name,
"CurrentUser": user.Name,
})
_, warnings, err := cmd.Actor.CreateApplicationInSpace(
resources.Application{
Name: cmd.RequiredArgs.AppName,
LifecycleType: constant.AppLifecycleType(cmd.AppType),
},
cmd.Config.TargetedSpace().GUID,
)
cmd.UI.DisplayWarnings(warnings)
if err != nil {
switch err.(type) {
case ccerror.NameNotUniqueInSpaceError:
cmd.UI.DisplayText(err.Error())
default:
return err
}
}
cmd.UI.DisplayOK()
return nil
}