func (cmd ListApps) Run(c *cli.Context) { cmd.ui.Say("Getting apps in org %s / space %s as %s...", terminal.EntityNameColor(cmd.config.OrganizationFields().Name), terminal.EntityNameColor(cmd.config.SpaceFields().Name), terminal.EntityNameColor(cmd.config.Username()), ) apps, apiErr := cmd.appSummaryRepo.GetSummariesInCurrentSpace() if apiErr != nil { cmd.ui.Failed(apiErr.Error()) return } cmd.ui.Ok() cmd.ui.Say("") if len(apps) == 0 { cmd.ui.Say("No apps found") return } table := terminal.NewTable(cmd.ui, []string{ "name", "requested state", "instances", "memory", "disk", "urls", }) rows := [][]string{} for _, application := range apps { var urls []string for _, route := range application.Routes { urls = append(urls, route.URL()) } rows = append(rows, []string{ application.Name, ui_helpers.ColoredAppState(application.ApplicationFields), ui_helpers.ColoredAppInstances(application.ApplicationFields), formatters.ByteSize(application.Memory * formatters.MEGABYTE), formatters.ByteSize(application.DiskQuota * formatters.MEGABYTE), strings.Join(urls, ", "), }) } table.Print(rows) }
func (cmd *ShowApp) ShowApp(app models.Application) { cmd.ui.Say("Showing health and status for app %s in org %s / space %s as %s...", terminal.EntityNameColor(app.Name), terminal.EntityNameColor(cmd.config.OrganizationFields().Name), terminal.EntityNameColor(cmd.config.SpaceFields().Name), terminal.EntityNameColor(cmd.config.Username()), ) application, apiErr := cmd.appSummaryRepo.GetSummary(app.Guid) appIsStopped := (application.State == "stopped") if err, ok := apiErr.(errors.HttpError); ok { if err.ErrorCode() == errors.APP_STOPPED || err.ErrorCode() == errors.APP_NOT_STAGED { appIsStopped = true } } if apiErr != nil && !appIsStopped { cmd.ui.Failed(apiErr.Error()) return } var instances []models.AppInstanceFields instances, apiErr = cmd.appInstancesRepo.GetInstances(app.Guid) if apiErr != nil && !appIsStopped { cmd.ui.Failed(apiErr.Error()) return } cmd.ui.Ok() cmd.ui.Say("\n%s %s", terminal.HeaderColor("requested state:"), ui_helpers.ColoredAppState(application.ApplicationFields)) cmd.ui.Say("%s %s", terminal.HeaderColor("instances:"), ui_helpers.ColoredAppInstances(application.ApplicationFields)) cmd.ui.Say("%s %s x %d instances", terminal.HeaderColor("usage:"), formatters.ByteSize(application.Memory*formatters.MEGABYTE), application.InstanceCount) var urls []string for _, route := range application.Routes { urls = append(urls, route.URL()) } cmd.ui.Say("%s %s\n", terminal.HeaderColor("urls:"), strings.Join(urls, ", ")) if appIsStopped { cmd.ui.Say("There are no running instances of this app.") return } table := terminal.NewTable(cmd.ui, []string{"", "state", "since", "cpu", "memory", "disk"}) rows := [][]string{} for index, instance := range instances { rows = append(rows, []string{ fmt.Sprintf("#%d", index), ui_helpers.ColoredInstanceState(instance), instance.Since.Format("2006-01-02 03:04:05 PM"), fmt.Sprintf("%.1f%%", instance.CpuUsage*100), fmt.Sprintf("%s of %s", formatters.ByteSize(instance.MemUsage), formatters.ByteSize(instance.MemQuota)), fmt.Sprintf("%s of %s", formatters.ByteSize(instance.DiskUsage), formatters.ByteSize(instance.DiskQuota)), }) } table.Print(rows) }