-
Notifications
You must be signed in to change notification settings - Fork 929
/
delete_route_command.go
74 lines (60 loc) · 2.28 KB
/
delete_route_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
package v7
import (
"code.cloudfoundry.org/cli/actor/actionerror"
"code.cloudfoundry.org/cli/command/flag"
)
type DeleteRouteCommand struct {
BaseCommand
RequiredArgs flag.Domain `positional-args:"yes"`
usage interface{} `usage:"CF_NAME delete-route DOMAIN [--hostname HOSTNAME] [--path PATH] [-f]\n\nEXAMPLES:\n CF_NAME delete-route example.com # example.com\n CF_NAME delete-route example.com --hostname myhost # myhost.example.com\n CF_NAME delete-route example.com --hostname myhost --path foo # myhost.example.com/foo"`
Force bool `short:"f" description:"Force deletion without confirmation"`
Hostname string `long:"hostname" short:"n" description:"Hostname used to identify the HTTP route (required for shared domains)"`
Path flag.V7RoutePath `long:"path" description:"Path used to identify the HTTP route"`
relatedCommands interface{} `related_commands:"delete-orphaned-routes, routes, unmap-route"`
}
func (cmd DeleteRouteCommand) Execute(args []string) error {
err := cmd.SharedActor.CheckTarget(true, false)
if err != nil {
return err
}
_, err = cmd.Config.CurrentUser()
if err != nil {
return err
}
domain := cmd.RequiredArgs.Domain
hostname := cmd.Hostname
pathName := cmd.Path.Path
url := desiredURL(domain, hostname, pathName, 0)
cmd.UI.DisplayText("This action impacts all apps using this route.")
cmd.UI.DisplayText("Deleting this route will make apps unreachable via this route.")
if !cmd.Force {
response, promptErr := cmd.UI.DisplayBoolPrompt(false, "Really delete the route {{.URL}}?", map[string]interface{}{
"URL": url,
})
if promptErr != nil {
return promptErr
}
if !response {
cmd.UI.DisplayText("'{{.URL}}' has not been deleted.", map[string]interface{}{
"URL": url,
})
return nil
}
}
cmd.UI.DisplayTextWithFlavor("Deleting route {{.URL}}...",
map[string]interface{}{
"URL": url,
})
warnings, err := cmd.Actor.DeleteRoute(domain, hostname, pathName)
cmd.UI.DisplayWarnings(warnings)
if err != nil {
if _, ok := err.(actionerror.RouteNotFoundError); ok {
cmd.UI.DisplayText(`Unable to delete. ` + err.Error())
cmd.UI.DisplayOK()
return nil
}
return err
}
cmd.UI.DisplayOK()
return nil
}