github.com/loafoe/cli@v7.1.0+incompatible/command/v7/check_route_command.go (about) 1 package v7 2 3 import ( 4 "code.cloudfoundry.org/cli/command/flag" 5 ) 6 7 type CheckRouteCommand struct { 8 BaseCommand 9 10 RequiredArgs flag.Domain `positional-args:"yes"` 11 Hostname string `long:"hostname" short:"n" description:"Hostname used to identify the HTTP route"` 12 Path flag.V7RoutePath `long:"path" description:"Path used to identify the HTTP route"` 13 Port int `long:"port" description:"Port used to identify the TCP route"` 14 relatedCommands interface{} `related_commands:"create-route, delete-route, routes"` 15 } 16 17 func (cmd CheckRouteCommand) Usage() string { 18 return ` 19 Check an HTTP route: 20 CF_NAME check-route DOMAIN [--hostname HOSTNAME] [--path PATH] 21 22 Check a TCP route: 23 CF_NAME check-route DOMAIN --port PORT` 24 } 25 26 func (cmd CheckRouteCommand) Examples() string { 27 return ` 28 CF_NAME check-route example.com # example.com 29 CF_NAME check-route example.com -n myhost --path foo # myhost.example.com/foo 30 CF_NAME check-route example.com --path foo # example.com/foo 31 CF_NAME check-route example.com --port 5000 # example.com:5000` 32 } 33 34 func (cmd CheckRouteCommand) Execute(args []string) error { 35 err := cmd.SharedActor.CheckTarget(true, false) 36 if err != nil { 37 return err 38 } 39 40 _, err = cmd.Config.CurrentUser() 41 if err != nil { 42 return err 43 } 44 45 cmd.UI.DisplayText("Checking for route...") 46 47 path := cmd.Path.Path 48 matches, warnings, err := cmd.Actor.CheckRoute(cmd.RequiredArgs.Domain, cmd.Hostname, path, cmd.Port) 49 cmd.UI.DisplayWarnings(warnings) 50 51 if err != nil { 52 return err 53 } 54 55 formatParams := map[string]interface{}{ 56 "URL": desiredURL(cmd.RequiredArgs.Domain, cmd.Hostname, path, cmd.Port), 57 } 58 59 if matches { 60 cmd.UI.DisplayText("Route '{{.URL}}' does exist.", formatParams) 61 } else { 62 cmd.UI.DisplayText("Route '{{.URL}}' does not exist.", formatParams) 63 } 64 65 cmd.UI.DisplayOK() 66 67 return nil 68 }