-
Notifications
You must be signed in to change notification settings - Fork 929
/
delete_command.go
87 lines (74 loc) · 2.43 KB
/
delete_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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package v7
import (
"code.cloudfoundry.org/cli/actor/actionerror"
"code.cloudfoundry.org/cli/command/flag"
)
type DeleteCommand struct {
BaseCommand
RequiredArgs flag.AppName `positional-args:"yes"`
Force bool `short:"f" description:"Force deletion without confirmation"`
DeleteMappedRoutes bool `short:"r" description:"Also delete any mapped routes"`
usage interface{} `usage:"CF_NAME delete APP_NAME [-r] [-f]"`
relatedCommands interface{} `related_commands:"apps, scale, stop"`
}
func (cmd DeleteCommand) Execute(args []string) error {
err := cmd.SharedActor.CheckTarget(true, true)
if err != nil {
return err
}
currentUser, err := cmd.Config.CurrentUser()
if err != nil {
return err
}
if !cmd.Force {
prompt := "Really delete the app {{.AppName}}?"
if cmd.DeleteMappedRoutes {
prompt = "Really delete the app {{.AppName}} and associated routes?"
cmd.UI.DisplayText("Deleting the app and associated routes will make apps with this route, in any org, unreachable.")
}
response, promptErr := cmd.UI.DisplayBoolPrompt(false, prompt, map[string]interface{}{
"AppName": cmd.RequiredArgs.AppName,
})
if promptErr != nil {
return promptErr
}
if !response {
cmd.UI.DisplayText("App '{{.AppName}}' has not been deleted.", map[string]interface{}{
"AppName": cmd.RequiredArgs.AppName,
})
return nil
}
}
cmd.UI.DisplayTextWithFlavor("Deleting app {{.AppName}} in org {{.OrgName}} / space {{.SpaceName}} as {{.Username}}...", map[string]interface{}{
"AppName": cmd.RequiredArgs.AppName,
"OrgName": cmd.Config.TargetedOrganization().Name,
"SpaceName": cmd.Config.TargetedSpace().Name,
"Username": currentUser.Name,
})
warnings, err := cmd.Actor.DeleteApplicationByNameAndSpace(
cmd.RequiredArgs.AppName,
cmd.Config.TargetedSpace().GUID,
cmd.DeleteMappedRoutes,
)
cmd.UI.DisplayWarnings(warnings)
if err != nil {
switch err.(type) {
case actionerror.ApplicationNotFoundError:
cmd.UI.DisplayWarning("App '{{.AppName}}' does not exist.", map[string]interface{}{
"AppName": cmd.RequiredArgs.AppName,
})
case actionerror.RouteBoundToMultipleAppsError:
cmd.UI.DeferText(
"\nTIP: Run 'cf delete {{.AppName}}' to delete the app and 'cf delete-route' to delete the route.",
map[string]interface{}{
"AppName": cmd.RequiredArgs.AppName,
},
)
return err
default:
return err
}
}
cmd.UI.DisplayOK()
return nil
}