MCPcopy Index your code
hub / github.com/cloudfoundry/cli / Execute

Method Execute

command/v7/enable_ssh_command.go:15–77  ·  view source on GitHub ↗
(args []string)

Source from the content-addressed store, hash-verified

13}
14
15func (cmd *EnableSSHCommand) Execute(args []string) error {
16 err := cmd.SharedActor.CheckTarget(true, true)
17 if err != nil {
18 return err
19 }
20
21 user, err := cmd.Actor.GetCurrentUser()
22 if err != nil {
23 return err
24 }
25
26 cmd.UI.DisplayTextWithFlavor("Enabling ssh support for app {{.AppName}} as {{.CurrentUserName}}...", map[string]interface{}{
27 "AppName": cmd.RequiredArgs.AppName,
28 "CurrentUserName": user.Name,
29 })
30
31 app, getAppWarnings, err := cmd.Actor.GetApplicationByNameAndSpace(cmd.RequiredArgs.AppName, cmd.Config.TargetedSpace().GUID)
32 if err != nil {
33 return err
34 }
35 cmd.UI.DisplayWarnings(getAppWarnings)
36
37 appFeature, getAppFeatureWarnings, err := cmd.Actor.GetAppFeature(app.GUID, "ssh")
38 if err != nil {
39 return err
40 }
41
42 cmd.UI.DisplayWarnings(getAppFeatureWarnings)
43
44 if appFeature.Enabled {
45 cmd.UI.DisplayTextWithFlavor("ssh support for app '{{.AppName}}' is already enabled.", map[string]interface{}{
46 "AppName": cmd.RequiredArgs.AppName,
47 })
48 }
49
50 updateSSHWarnings, err := cmd.Actor.UpdateAppFeature(app, true, "ssh")
51 if err != nil {
52 return err
53 }
54 cmd.UI.DisplayWarnings(updateSSHWarnings)
55
56 sshEnabled, getSSHEnabledWarnings, err := cmd.Actor.GetSSHEnabled(app.GUID)
57 if err != nil {
58 return err
59 }
60 cmd.UI.DisplayWarnings(getSSHEnabledWarnings)
61
62 cmd.UI.DisplayOK()
63
64 if !sshEnabled.Enabled {
65 cmd.UI.DisplayText("TIP: Ensure ssh is also enabled on the space and global level.")
66 }
67
68 if sshEnabled.Enabled && !appFeature.Enabled {
69 cmd.UI.DisplayText("TIP: An app restart is required for the change to take effect.")
70 }
71
72 if appFeature.Enabled {

Callers

nothing calls this directly

Calls 11

CheckTargetMethod · 0.65
GetCurrentUserMethod · 0.65
DisplayTextWithFlavorMethod · 0.65
TargetedSpaceMethod · 0.65
DisplayWarningsMethod · 0.65
GetAppFeatureMethod · 0.65
UpdateAppFeatureMethod · 0.65
GetSSHEnabledMethod · 0.65
DisplayOKMethod · 0.65
DisplayTextMethod · 0.65

Tested by

no test coverage detected