github.com/loafoe/cli@v7.1.0+incompatible/command/v7/purge_service_offering_command.go (about) 1 package v7 2 3 import ( 4 "code.cloudfoundry.org/cli/api/cloudcontroller/ccerror" 5 "code.cloudfoundry.org/cli/command/flag" 6 ) 7 8 type PurgeServiceOfferingCommand struct { 9 BaseCommand 10 11 RequiredArgs flag.Service `positional-args:"yes"` 12 ServiceBroker string `short:"b" description:"Purge a service offering from a particular service broker. Required when service offering name is ambiguous"` 13 Force bool `short:"f" description:"Force deletion without confirmation"` 14 usage interface{} `usage:"CF_NAME purge-service-offering SERVICE [-b BROKER] [-f]\n\nWARNING: This operation assumes that the service broker responsible for this service offering is no longer available, and all service instances have been deleted, leaving orphan records in Cloud Foundry's database. All knowledge of the service offering will be removed from Cloud Foundry, including service instances and service bindings. No attempt will be made to contact the service broker; running this command without destroying the service broker will cause orphan service instances. After running this command you may want to run either delete-service-auth-token or delete-service-broker to complete the cleanup."` 15 relatedCommands interface{} `related_commands:"marketplace, purge-service-instance, service-brokers"` 16 } 17 18 func (cmd PurgeServiceOfferingCommand) Execute(args []string) error { 19 if err := cmd.SharedActor.CheckTarget(false, false); err != nil { 20 return err 21 } 22 23 if !cmd.Force { 24 cmd.UI.DisplayText("WARNING: This operation assumes that the service broker responsible for this service offering is no longer available, and all service instances have been deleted, leaving orphan records in Cloud Foundry's database. All knowledge of the service offering will be removed from Cloud Foundry, including service instances and service bindings. No attempt will be made to contact the service broker; running this command without destroying the service broker will cause orphan service instances. After running this command you may want to run either delete-service-auth-token or delete-service-broker to complete the cleanup.\n") 25 26 confirmed, err := cmd.confirmationPrompt() 27 if err != nil { 28 return err 29 } 30 if !confirmed { 31 cmd.UI.DisplayText("Purge service offering cancelled.\n") 32 return nil 33 } 34 } 35 36 cmd.UI.DisplayText("Purging service offering {{.ServiceOffering}}...", map[string]interface{}{ 37 "ServiceOffering": cmd.RequiredArgs.ServiceOffering, 38 }) 39 40 warnings, err := cmd.Actor.PurgeServiceOfferingByNameAndBroker(cmd.RequiredArgs.ServiceOffering, cmd.ServiceBroker) 41 cmd.UI.DisplayWarnings(warnings) 42 if err != nil { 43 switch err.(type) { 44 case ccerror.ServiceOfferingNotFoundError: 45 cmd.UI.DisplayText("Service offering '{{.ServiceOffering}}' not found.", map[string]interface{}{ 46 "ServiceOffering": cmd.RequiredArgs.ServiceOffering, 47 }) 48 default: 49 return err 50 } 51 } 52 53 cmd.UI.DisplayOK() 54 55 return nil 56 } 57 58 func (cmd PurgeServiceOfferingCommand) confirmationPrompt() (bool, error) { 59 var promptMessage string 60 if cmd.ServiceBroker != "" { 61 promptMessage = "Really purge service offering {{.ServiceOffering}} from broker {{.ServiceBroker}} from Cloud Foundry?" 62 } else { 63 promptMessage = "Really purge service offering {{.ServiceOffering}} from Cloud Foundry?" 64 } 65 66 return cmd.UI.DisplayBoolPrompt(false, promptMessage, map[string]interface{}{ 67 "ServiceOffering": cmd.RequiredArgs.ServiceOffering, 68 "ServiceBroker": cmd.ServiceBroker, 69 }) 70 }