github.com/franc20/ayesa_sap@v7.0.0-beta.28.0.20200124003224-302d4d52fa6c+incompatible/command/v6/delete_orphaned_routes_command.go (about) 1 package v6 2 3 import ( 4 "code.cloudfoundry.org/cli/actor/sharedaction" 5 "code.cloudfoundry.org/cli/actor/v2action" 6 "code.cloudfoundry.org/cli/command" 7 "code.cloudfoundry.org/cli/command/v6/shared" 8 ) 9 10 //go:generate counterfeiter . DeleteOrphanedRoutesActor 11 12 type DeleteOrphanedRoutesActor interface { 13 DeleteUnmappedRoutes(spaceGUID string) (v2action.Warnings, error) 14 } 15 16 type DeleteOrphanedRoutesCommand struct { 17 Force bool `short:"f" description:"Force deletion without confirmation"` 18 usage interface{} `usage:"CF_NAME delete-orphaned-routes [-f]"` 19 relatedCommands interface{} `related_commands:"delete-route, routes"` 20 21 UI command.UI 22 Actor DeleteOrphanedRoutesActor 23 SharedActor command.SharedActor 24 Config command.Config 25 } 26 27 func (cmd *DeleteOrphanedRoutesCommand) Setup(config command.Config, ui command.UI) error { 28 cmd.UI = ui 29 cmd.Config = config 30 cmd.SharedActor = sharedaction.NewActor(config) 31 32 ccClient, uaaClient, err := shared.GetNewClientsAndConnectToCF(config, ui) 33 if err != nil { 34 return err 35 } 36 cmd.Actor = v2action.NewActor(ccClient, uaaClient, config) 37 38 return nil 39 } 40 41 func (cmd *DeleteOrphanedRoutesCommand) Execute(args []string) error { 42 err := cmd.SharedActor.CheckTarget(true, true) 43 if err != nil { 44 return err 45 } 46 47 user, err := cmd.Config.CurrentUser() 48 if err != nil { 49 return err 50 } 51 52 if !cmd.Force { 53 deleteOrphanedRoutes, promptErr := cmd.UI.DisplayBoolPrompt(false, "Really delete orphaned routes?") 54 if promptErr != nil { 55 return promptErr 56 } 57 58 if !deleteOrphanedRoutes { 59 return nil 60 } 61 } 62 63 cmd.UI.DisplayTextWithFlavor("Deleting routes as {{.CurrentUser}} ...", map[string]interface{}{ 64 "CurrentUser": user.Name, 65 }) 66 cmd.UI.DisplayNewline() 67 68 warnings, err := cmd.Actor.DeleteUnmappedRoutes(cmd.Config.TargetedSpace().GUID) 69 cmd.UI.DisplayWarnings(warnings) 70 if err != nil { 71 return err 72 } 73 74 cmd.UI.DisplayOK() 75 76 return nil 77 }