github.com/loafoe/cli@v7.1.0+incompatible/command/v7/delete_route_command.go (about) 1 package v7 2 3 import ( 4 "code.cloudfoundry.org/cli/actor/actionerror" 5 "code.cloudfoundry.org/cli/command/flag" 6 ) 7 8 type DeleteRouteCommand struct { 9 BaseCommand 10 11 RequiredArgs flag.Domain `positional-args:"yes"` 12 Force bool `short:"f" description:"Force deletion without confirmation"` 13 Hostname string `long:"hostname" short:"n" description:"Hostname used to identify the HTTP route (required for shared domains)"` 14 Path flag.V7RoutePath `long:"path" description:"Path used to identify the HTTP route"` 15 Port int `long:"port" description:"Port used to identify the TCP route"` 16 relatedCommands interface{} `related_commands:"delete-orphaned-routes, routes, unmap-route"` 17 } 18 19 func (cmd DeleteRouteCommand) Usage() string { 20 return ` 21 Delete an HTTP route: 22 CF_NAME delete-route DOMAIN [--hostname HOSTNAME] [--path PATH] [-f] 23 24 Delete a TCP route: 25 CF_NAME delete-route DOMAIN --port PORT [-f]` 26 } 27 28 func (cmd DeleteRouteCommand) Examples() string { 29 return ` 30 CF_NAME delete-route example.com # example.com 31 CF_NAME delete-route example.com --hostname myhost # myhost.example.com 32 CF_NAME delete-route example.com --hostname myhost --path foo # myhost.example.com/foo 33 CF_NAME delete-route example.com --port 5000 # example.com:5000` 34 } 35 36 func (cmd DeleteRouteCommand) Execute(args []string) error { 37 err := cmd.SharedActor.CheckTarget(true, false) 38 if err != nil { 39 return err 40 } 41 42 _, err = cmd.Config.CurrentUser() 43 if err != nil { 44 return err 45 } 46 47 url := desiredURL(cmd.RequiredArgs.Domain, cmd.Hostname, cmd.Path.Path, cmd.Port) 48 49 cmd.UI.DisplayText("This action impacts all apps using this route.") 50 cmd.UI.DisplayText("Deleting this route will make apps unreachable via this route.") 51 52 if !cmd.Force { 53 response, promptErr := cmd.UI.DisplayBoolPrompt(false, "Really delete the route {{.URL}}?", map[string]interface{}{ 54 "URL": url, 55 }) 56 57 if promptErr != nil { 58 return promptErr 59 } 60 61 if !response { 62 cmd.UI.DisplayText("'{{.URL}}' has not been deleted.", map[string]interface{}{ 63 "URL": url, 64 }) 65 return nil 66 } 67 } 68 69 cmd.UI.DisplayTextWithFlavor("Deleting route {{.URL}}...", 70 map[string]interface{}{ 71 "URL": url, 72 }) 73 74 warnings, err := cmd.Actor.DeleteRoute(cmd.RequiredArgs.Domain, cmd.Hostname, cmd.Path.Path, cmd.Port) 75 76 cmd.UI.DisplayWarnings(warnings) 77 if err != nil { 78 if _, ok := err.(actionerror.RouteNotFoundError); ok { 79 cmd.UI.DisplayText(`Unable to delete. ` + err.Error()) 80 cmd.UI.DisplayOK() 81 return nil 82 } 83 return err 84 } 85 86 cmd.UI.DisplayOK() 87 return nil 88 }