github.com/jenspinney/cli@v6.42.1-0.20190207184520-7450c600020e+incompatible/command/v6/get_health_check_command.go (about)

     1  package v6
     2  
     3  import (
     4  	"code.cloudfoundry.org/cli/actor/sharedaction"
     5  	"code.cloudfoundry.org/cli/actor/v2action"
     6  	"code.cloudfoundry.org/cli/command"
     7  	"code.cloudfoundry.org/cli/command/flag"
     8  	"code.cloudfoundry.org/cli/command/v6/shared"
     9  )
    10  
    11  //go:generate counterfeiter . GetHealthCheckActor
    12  type GetHealthCheckActor interface {
    13  	GetApplicationByNameAndSpace(name string, spaceGUID string) (v2action.Application, v2action.Warnings, error)
    14  }
    15  
    16  type GetHealthCheckCommand struct {
    17  	RequiredArgs flag.AppName `positional-args:"yes"`
    18  	usage        interface{}  `usage:"CF_NAME get-health-check APP_NAME"`
    19  
    20  	UI          command.UI
    21  	Config      command.Config
    22  	SharedActor command.SharedActor
    23  	Actor       GetHealthCheckActor
    24  }
    25  
    26  func (cmd *GetHealthCheckCommand) Setup(config command.Config, ui command.UI) error {
    27  	cmd.Config = config
    28  	cmd.UI = ui
    29  	cmd.SharedActor = sharedaction.NewActor(config)
    30  
    31  	ccClient, uaaClient, err := shared.NewClients(config, ui, true)
    32  	if err != nil {
    33  		return err
    34  	}
    35  	cmd.Actor = v2action.NewActor(ccClient, uaaClient, config)
    36  
    37  	return nil
    38  }
    39  
    40  func (cmd GetHealthCheckCommand) Execute(args []string) error {
    41  	err := cmd.SharedActor.CheckTarget(true, true)
    42  	if err != nil {
    43  		return err
    44  	}
    45  
    46  	user, err := cmd.Config.CurrentUser()
    47  	if err != nil {
    48  		return err
    49  	}
    50  
    51  	cmd.UI.DisplayTextWithFlavor("Getting health check type for app {{.AppName}} in org {{.OrgName}} / space {{.SpaceName}} as {{.Username}}...",
    52  		map[string]interface{}{
    53  			"AppName":   cmd.RequiredArgs.AppName,
    54  			"OrgName":   cmd.Config.TargetedOrganization().Name,
    55  			"SpaceName": cmd.Config.TargetedSpace().Name,
    56  			"Username":  user.Name,
    57  		})
    58  
    59  	app, warnings, err := cmd.Actor.GetApplicationByNameAndSpace(
    60  		cmd.RequiredArgs.AppName,
    61  		cmd.Config.TargetedSpace().GUID,
    62  	)
    63  
    64  	cmd.UI.DisplayWarnings(warnings)
    65  
    66  	if err != nil {
    67  		return err
    68  	}
    69  
    70  	cmd.UI.DisplayNewline()
    71  
    72  	table := [][]string{
    73  		{cmd.UI.TranslateText("health check type:"), string(app.HealthCheckType)},
    74  		{cmd.UI.TranslateText("endpoint (for http type):"), app.CalculatedHealthCheckEndpoint()},
    75  	}
    76  
    77  	cmd.UI.DisplayKeyValueTable("", table, 3)
    78  
    79  	return nil
    80  }