forked from cloudfoundry/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_route_command.go
68 lines (53 loc) · 1.87 KB
/
check_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
package v7
import (
"code.cloudfoundry.org/cli/command/flag"
)
type CheckRouteCommand struct {
BaseCommand
RequiredArgs flag.Domain `positional-args:"yes"`
Hostname string `long:"hostname" short:"n" description:"Hostname used to identify the HTTP route"`
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:"create-route, delete-route, routes"`
}
func (cmd CheckRouteCommand) Usage() string {
return `
Check an HTTP route:
CF_NAME check-route DOMAIN [--hostname HOSTNAME] [--path PATH]
Check a TCP route:
CF_NAME check-route DOMAIN --port PORT`
}
func (cmd CheckRouteCommand) Examples() string {
return `
CF_NAME check-route example.com # example.com
CF_NAME check-route example.com -n myhost --path foo # myhost.example.com/foo
CF_NAME check-route example.com --path foo # example.com/foo
CF_NAME check-route example.com --port 5000 # example.com:5000`
}
func (cmd CheckRouteCommand) Execute(args []string) error {
err := cmd.SharedActor.CheckTarget(true, false)
if err != nil {
return err
}
_, err = cmd.Config.CurrentUser()
if err != nil {
return err
}
cmd.UI.DisplayText("Checking for route...")
path := cmd.Path.Path
matches, warnings, err := cmd.Actor.CheckRoute(cmd.RequiredArgs.Domain, cmd.Hostname, path, cmd.Port)
cmd.UI.DisplayWarnings(warnings)
if err != nil {
return err
}
formatParams := map[string]interface{}{
"URL": desiredURL(cmd.RequiredArgs.Domain, cmd.Hostname, path, cmd.Port),
}
if matches {
cmd.UI.DisplayText("Route '{{.URL}}' does exist.", formatParams)
} else {
cmd.UI.DisplayText("Route '{{.URL}}' does not exist.", formatParams)
}
cmd.UI.DisplayOK()
return nil
}