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