示例#1
0
文件: push.go 项目: jalateras/cli
func (cmd Push) createApp(appName string, c *cli.Context) (app cf.Application, apiResponse net.ApiResponse) {
	newApp := cf.Application{
		Name:         appName,
		Instances:    c.Int("i"),
		Memory:       memoryLimit(c.String("m")),
		BuildpackUrl: c.String("b"),
		Command:      c.String("c"),
	}

	stackName := c.String("s")
	if stackName != "" {
		var stack cf.Stack
		stack, apiResponse = cmd.stackRepo.FindByName(stackName)

		if apiResponse.IsNotSuccessful() {
			cmd.ui.Failed(apiResponse.Message)
			return
		}
		newApp.Stack = stack
		cmd.ui.Say("Using stack %s...", terminal.EntityNameColor(stack.Name))
	}

	cmd.ui.Say("Creating app %s in org %s / space %s as %s...",
		terminal.EntityNameColor(appName),
		terminal.EntityNameColor(cmd.config.Organization.Name),
		terminal.EntityNameColor(cmd.config.Space.Name),
		terminal.EntityNameColor(cmd.config.Username()),
	)
	app, apiResponse = cmd.appRepo.Create(newApp)
	if apiResponse.IsNotSuccessful() {
		cmd.ui.Failed(apiResponse.Message)
		return
	}

	cmd.ui.Ok()
	cmd.ui.Say("")

	return
}
示例#2
0
文件: push.go 项目: KaiYoung/cli
func (p Push) createApp(appName string, c *cli.Context) (app cf.Application, err error) {
	newApp := cf.Application{
		Name:         appName,
		Instances:    c.Int("instances"),
		Memory:       getMemoryLimit(c.String("memory")),
		BuildpackUrl: c.String("buildpack"),
	}

	stackName := c.String("stack")
	if stackName != "" {
		var stack cf.Stack
		stack, err = p.stackRepo.FindByName(stackName)

		if err != nil {
			p.ui.Failed("Error finding stack", err)
			return
		}
		newApp.Stack = stack
		p.ui.Say("Using stack %s.", stack.Name)
	}

	p.ui.Say("Creating %s...", appName)
	app, err = p.appRepo.Create(newApp)
	if err != nil {
		p.ui.Failed("Error creating application", err)
		return
	}
	p.ui.Ok()

	domain, err := p.domainRepo.FindByName(c.String("domain"))

	if err != nil {
		p.ui.Failed("Error loading domain", err)
		return
	}

	hostName := c.String("host")
	if hostName == "" {
		hostName = app.Name
	}

	route, err := p.routeRepo.FindByHost(hostName)
	if err != nil {
		newRoute := cf.Route{Host: hostName}

		p.ui.Say("Creating route %s.%s...", newRoute.Host, domain.Name)
		route, err = p.routeRepo.Create(newRoute, domain)
		if err != nil {
			p.ui.Failed("Error creating route", err)
			return
		}
		p.ui.Ok()
	} else {
		p.ui.Say("Using route %s.%s", route.Host, domain.Name)
	}

	p.ui.Say("Binding %s.%s to %s...", route.Host, domain.Name, app.Name)
	err = p.routeRepo.Bind(route, app)
	if err != nil {
		p.ui.Failed("Error binding route", err)
		return
	}
	p.ui.Ok()

	return
}