forked from cloudfoundry/cli
/
delete_route_command.go
88 lines (71 loc) · 2.58 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
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"`
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"`
Port int `long:"port" description:"Port used to identify the TCP route"`
relatedCommands interface{} `related_commands:"delete-orphaned-routes, routes, unmap-route"`
}
func (cmd DeleteRouteCommand) Usage() string {
return `
Delete an HTTP route:
CF_NAME delete-route DOMAIN [--hostname HOSTNAME] [--path PATH] [-f]
Delete a TCP route:
CF_NAME delete-route DOMAIN --port PORT [-f]`
}
func (cmd DeleteRouteCommand) Examples() string {
return `
CF_NAME delete-route example.com # example.com
CF_NAME delete-route example.com --hostname myhost # myhost.example.com
CF_NAME delete-route example.com --hostname myhost --path foo # myhost.example.com/foo
CF_NAME delete-route example.com --port 5000 # example.com:5000`
}
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
}
url := desiredURL(cmd.RequiredArgs.Domain, cmd.Hostname, cmd.Path.Path, cmd.Port)
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(cmd.RequiredArgs.Domain, cmd.Hostname, cmd.Path.Path, cmd.Port)
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
}