github.com/niteshexa/cloudfoundry_cli@v7.1.0+incompatible/command/v7/restart_app_instance_command.go (about)

     1  package v7
     2  
     3  import (
     4  	"code.cloudfoundry.org/cli/command/flag"
     5  )
     6  
     7  type RestartAppInstanceCommand struct {
     8  	BaseCommand
     9  
    10  	RequiredArgs    flag.AppInstance `positional-args:"yes"`
    11  	ProcessType     string           `long:"process" default:"web" description:"Process to restart"`
    12  	usage           interface{}      `usage:"CF_NAME restart-app-instance APP_NAME INDEX [--process PROCESS]"`
    13  	relatedCommands interface{}      `related_commands:"restart"`
    14  }
    15  
    16  func (cmd RestartAppInstanceCommand) Execute(args []string) error {
    17  	err := cmd.SharedActor.CheckTarget(true, true)
    18  	if err != nil {
    19  		return err
    20  	}
    21  
    22  	user, err := cmd.Config.CurrentUser()
    23  	if err != nil {
    24  		return err
    25  	}
    26  
    27  	cmd.UI.DisplayTextWithFlavor("Restarting instance {{.InstanceIndex}} of process {{.ProcessType}} of app {{.AppName}} in org {{.OrgName}} / space {{.SpaceName}} as {{.Username}}...", map[string]interface{}{
    28  		"InstanceIndex": cmd.RequiredArgs.Index,
    29  		"ProcessType":   cmd.ProcessType,
    30  		"AppName":       cmd.RequiredArgs.AppName,
    31  		"Username":      user.Name,
    32  		"OrgName":       cmd.Config.TargetedOrganization().Name,
    33  		"SpaceName":     cmd.Config.TargetedSpace().Name,
    34  	})
    35  
    36  	warnings, err := cmd.Actor.DeleteInstanceByApplicationNameSpaceProcessTypeAndIndex(cmd.RequiredArgs.AppName, cmd.Config.TargetedSpace().GUID, cmd.ProcessType, cmd.RequiredArgs.Index)
    37  	cmd.UI.DisplayWarnings(warnings)
    38  	if err != nil {
    39  		return err
    40  	}
    41  
    42  	cmd.UI.DisplayOK()
    43  	return nil
    44  }