func (cmd *Scale) Run(c *cli.Context) { currentApp := cmd.appReq.GetApplication() cmd.ui.Say("Scaling app %s in org %s / space %s as %s...", terminal.EntityNameColor(currentApp.Name), terminal.EntityNameColor(cmd.config.OrganizationFields().Name), terminal.EntityNameColor(cmd.config.SpaceFields().Name), terminal.EntityNameColor(cmd.config.Username()), ) params := models.AppParams{} shouldRestart := false if c.String("m") != "" { memory, err := formatters.ToMegabytes(c.String("m")) if err != nil { cmd.ui.Say("Invalid value for memory") cmd.ui.FailWithUsage(c, "scale") return } params.Memory = &memory shouldRestart = true } instances := c.Int("i") if instances != -1 { params.InstanceCount = &instances } updatedApp, apiResponse := cmd.appRepo.Update(currentApp.Guid, params) if apiResponse.IsNotSuccessful() { cmd.ui.Failed(apiResponse.Message) return } cmd.ui.Ok() cmd.ui.Say("") if shouldRestart { cmd.restarter.ApplicationRestart(updatedApp) } }
func (cmd *Scale) Run(c *cli.Context) { currentApp := cmd.appReq.GetApplication() if !anyFlagsSet(c) { cmd.ui.Say("Showing current scale of app %s in org %s / space %s as %s...", terminal.EntityNameColor(currentApp.Name), terminal.EntityNameColor(cmd.config.OrganizationFields().Name), terminal.EntityNameColor(cmd.config.SpaceFields().Name), terminal.EntityNameColor(cmd.config.Username()), ) cmd.ui.Ok() cmd.ui.Say("") cmd.ui.Say("%s %s", terminal.HeaderColor("memory:"), formatters.ByteSize(currentApp.Memory*bytesInAMegabyte)) cmd.ui.Say("%s %s", terminal.HeaderColor("disk:"), formatters.ByteSize(currentApp.DiskQuota*bytesInAMegabyte)) cmd.ui.Say("%s %d", terminal.HeaderColor("instances:"), currentApp.InstanceCount) return } params := models.AppParams{} shouldRestart := false if c.String("m") != "" { memory, err := formatters.ToMegabytes(c.String("m")) if err != nil { cmd.ui.Failed("Invalid memory limit: %s\n%s", c.String("m"), err) } params.Memory = &memory shouldRestart = true } if c.String("k") != "" { diskQuota, err := formatters.ToMegabytes(c.String("k")) if err != nil { cmd.ui.Failed("Invalid disk quota: %s\n%s", c.String("k"), err) } params.DiskQuota = &diskQuota shouldRestart = true } if c.IsSet("i") { instances := c.Int("i") if instances > 0 { params.InstanceCount = &instances } else { cmd.ui.Failed("Invalid instance count: %d\nInstance count must be a positive integer", instances) } } if shouldRestart && !cmd.confirmRestart(c, currentApp.Name) { return } cmd.ui.Say("Scaling app %s in org %s / space %s as %s...", terminal.EntityNameColor(currentApp.Name), terminal.EntityNameColor(cmd.config.OrganizationFields().Name), terminal.EntityNameColor(cmd.config.SpaceFields().Name), terminal.EntityNameColor(cmd.config.Username()), ) updatedApp, apiErr := cmd.appRepo.Update(currentApp.Guid, params) if apiErr != nil { cmd.ui.Failed(apiErr.Error()) return } cmd.ui.Ok() if shouldRestart { cmd.restarter.ApplicationRestart(updatedApp) } }