github.com/arunkumar7540/cli@v6.45.0+incompatible/command/v7/delete_shared_domain_command.go (about) 1 package v7 2 3 import ( 4 "code.cloudfoundry.org/cli/actor/actionerror" 5 "code.cloudfoundry.org/cli/actor/sharedaction" 6 "code.cloudfoundry.org/cli/actor/v7action" 7 "code.cloudfoundry.org/cli/command" 8 "code.cloudfoundry.org/cli/command/flag" 9 "code.cloudfoundry.org/cli/command/v7/shared" 10 ) 11 12 //go:generate counterfeiter . DeleteSharedDomainActor 13 14 type DeleteSharedDomainActor interface { 15 DeleteSharedDomain(domainName string) (v7action.Warnings, error) 16 } 17 18 type DeleteSharedDomainCommand struct { 19 RequiredArgs flag.Domain `positional-args:"yes"` 20 Force bool `short:"f" description:"Force deletion without confirmation"` 21 usage interface{} `usage:"CF_NAME delete-shared-domain DOMAIN [-f]"` 22 relatedCommands interface{} `related_commands:"delete-private-domain, domains"` 23 24 UI command.UI 25 Config command.Config 26 SharedActor command.SharedActor 27 Actor DeleteSharedDomainActor 28 } 29 30 func (cmd *DeleteSharedDomainCommand) Setup(config command.Config, ui command.UI) error { 31 cmd.UI = ui 32 cmd.Config = config 33 cmd.SharedActor = sharedaction.NewActor(config) 34 35 ccClient, _, err := shared.NewClients(config, ui, true, "") 36 if err != nil { 37 return err 38 } 39 cmd.Actor = v7action.NewActor(ccClient, config, nil, nil) 40 41 return nil 42 } 43 44 func (cmd DeleteSharedDomainCommand) Execute(args []string) error { 45 err := cmd.SharedActor.CheckTarget(true, false) 46 if err != nil { 47 return err 48 } 49 50 currentUser, err := cmd.Config.CurrentUser() 51 if err != nil { 52 return err 53 } 54 cmd.UI.DisplayText("This action impacts all orgs using this domain.") 55 cmd.UI.DisplayText("Deleting the domain will remove associated routes which will make apps with this domain, in any org, unreachable.") 56 57 if !cmd.Force { 58 response, promptErr := cmd.UI.DisplayBoolPrompt(false, "Really delete the shared domain {{.DomainName}}?", map[string]interface{}{ 59 "DomainName": cmd.RequiredArgs.Domain, 60 }) 61 62 if promptErr != nil { 63 return promptErr 64 } 65 66 if !response { 67 cmd.UI.DisplayText("'{{.DomainName}}' has not been deleted.", map[string]interface{}{ 68 "DomainName": cmd.RequiredArgs.Domain, 69 }) 70 return nil 71 } 72 } 73 cmd.UI.DisplayTextWithFlavor("Deleting domain {{.DomainName}} as {{.Username}}...", map[string]interface{}{ 74 "DomainName": cmd.RequiredArgs.Domain, 75 "Username": currentUser.Name, 76 }) 77 78 warnings, err := cmd.Actor.DeleteSharedDomain(cmd.RequiredArgs.Domain) 79 cmd.UI.DisplayWarnings(warnings) 80 if err != nil { 81 switch err.(type) { 82 case actionerror.DomainNotFoundError: 83 cmd.UI.DisplayTextWithFlavor("Domain {{.DomainName}} does not exist", map[string]interface{}{ 84 "DomainName": cmd.RequiredArgs.Domain, 85 }) 86 default: 87 return err 88 } 89 } 90 91 cmd.UI.DisplayOK() 92 93 return nil 94 }