github.com/loafoe/cli@v7.1.0+incompatible/command/v7/app_command.go (about)

     1  package v7
     2  
     3  import (
     4  	"code.cloudfoundry.org/cli/command/flag"
     5  	"code.cloudfoundry.org/cli/command/v7/shared"
     6  )
     7  
     8  type AppCommand struct {
     9  	BaseCommand
    10  
    11  	RequiredArgs    flag.AppName `positional-args:"yes"`
    12  	GUID            bool         `long:"guid" description:"Retrieve and display the given app's guid.  All other health and status output for the app is suppressed."`
    13  	usage           interface{}  `usage:"CF_NAME app APP_NAME [--guid]"`
    14  	relatedCommands interface{}  `related_commands:"apps, events, logs, map-route, unmap-route, push"`
    15  }
    16  
    17  func (cmd AppCommand) Execute(args []string) error {
    18  	err := cmd.SharedActor.CheckTarget(true, true)
    19  	if err != nil {
    20  		return err
    21  	}
    22  
    23  	if cmd.GUID {
    24  		return cmd.displayAppGUID()
    25  	}
    26  
    27  	user, err := cmd.Config.CurrentUser()
    28  	if err != nil {
    29  		return err
    30  	}
    31  
    32  	cmd.UI.DisplayTextWithFlavor("Showing health and status for app {{.AppName}} in org {{.OrgName}} / space {{.SpaceName}} as {{.Username}}...", map[string]interface{}{
    33  		"AppName":   cmd.RequiredArgs.AppName,
    34  		"OrgName":   cmd.Config.TargetedOrganization().Name,
    35  		"SpaceName": cmd.Config.TargetedSpace().Name,
    36  		"Username":  user.Name,
    37  	})
    38  	cmd.UI.DisplayNewline()
    39  
    40  	appSummaryDisplayer := shared.NewAppSummaryDisplayer(cmd.UI)
    41  	summary, warnings, err := cmd.Actor.GetDetailedAppSummary(cmd.RequiredArgs.AppName, cmd.Config.TargetedSpace().GUID, false)
    42  	cmd.UI.DisplayWarnings(warnings)
    43  	if err != nil {
    44  		return err
    45  	}
    46  
    47  	appSummaryDisplayer.AppDisplay(summary, false)
    48  	return nil
    49  }
    50  
    51  func (cmd AppCommand) displayAppGUID() error {
    52  	app, warnings, err := cmd.Actor.GetApplicationByNameAndSpace(cmd.RequiredArgs.AppName, cmd.Config.TargetedSpace().GUID)
    53  	cmd.UI.DisplayWarnings(warnings)
    54  	if err != nil {
    55  		return err
    56  	}
    57  
    58  	cmd.UI.DisplayText(app.GUID)
    59  	return nil
    60  }