github.com/orange-cloudfoundry/cli@v7.1.0+incompatible/command/v7/get_health_check_command.go (about) 1 package v7 2 3 import ( 4 "fmt" 5 6 "code.cloudfoundry.org/cli/actor/v7action" 7 "code.cloudfoundry.org/cli/command/flag" 8 "code.cloudfoundry.org/cli/util/ui" 9 ) 10 11 type GetHealthCheckCommand struct { 12 BaseCommand 13 14 RequiredArgs flag.AppName `positional-args:"yes"` 15 usage interface{} `usage:"CF_NAME get-health-check APP_NAME"` 16 } 17 18 func (cmd GetHealthCheckCommand) Execute(args []string) error { 19 err := cmd.SharedActor.CheckTarget(true, true) 20 if err != nil { 21 return err 22 } 23 24 user, err := cmd.Config.CurrentUser() 25 if err != nil { 26 return err 27 } 28 29 cmd.UI.DisplayTextWithFlavor("Getting health check type for app {{.AppName}} in org {{.OrgName}} / space {{.SpaceName}} as {{.Username}}...", map[string]interface{}{ 30 "AppName": cmd.RequiredArgs.AppName, 31 "OrgName": cmd.Config.TargetedOrganization().Name, 32 "SpaceName": cmd.Config.TargetedSpace().Name, 33 "Username": user.Name, 34 }) 35 36 processHealthChecks, warnings, err := cmd.Actor.GetApplicationProcessHealthChecksByNameAndSpace(cmd.RequiredArgs.AppName, cmd.Config.TargetedSpace().GUID) 37 cmd.UI.DisplayWarnings(warnings) 38 if err != nil { 39 return err 40 } 41 42 cmd.UI.DisplayNewline() 43 44 if len(processHealthChecks) == 0 { 45 cmd.UI.DisplayText("App has no processes") 46 return nil 47 } 48 49 return cmd.DisplayProcessTable(processHealthChecks) 50 } 51 52 func (cmd GetHealthCheckCommand) DisplayProcessTable(processHealthChecks []v7action.ProcessHealthCheck) error { 53 table := [][]string{ 54 { 55 cmd.UI.TranslateText("process"), 56 cmd.UI.TranslateText("health check"), 57 cmd.UI.TranslateText("endpoint (for http)"), 58 cmd.UI.TranslateText("invocation timeout"), 59 }, 60 } 61 62 for _, healthCheck := range processHealthChecks { 63 invocationTimeout := healthCheck.InvocationTimeout 64 if invocationTimeout == 0 { 65 invocationTimeout = 1 66 } 67 68 table = append(table, []string{ 69 healthCheck.ProcessType, 70 string(healthCheck.HealthCheckType), 71 healthCheck.Endpoint, 72 fmt.Sprint(invocationTimeout), 73 }) 74 } 75 76 cmd.UI.DisplayTableWithHeader("", table, ui.DefaultTableSpacePadding) 77 78 return nil 79 }