github.com/mook-as/cf-cli@v7.0.0-beta.28.0.20200120190804-b91c115fae48+incompatible/cf/commands/organization/unshare_private_domain.go (about) 1 package organization 2 3 import ( 4 "fmt" 5 6 "code.cloudfoundry.org/cli/cf/api" 7 "code.cloudfoundry.org/cli/cf/api/organizations" 8 "code.cloudfoundry.org/cli/cf/commandregistry" 9 "code.cloudfoundry.org/cli/cf/configuration/coreconfig" 10 "code.cloudfoundry.org/cli/cf/flags" 11 . "code.cloudfoundry.org/cli/cf/i18n" 12 "code.cloudfoundry.org/cli/cf/requirements" 13 "code.cloudfoundry.org/cli/cf/terminal" 14 ) 15 16 type UnsharePrivateDomain struct { 17 ui terminal.UI 18 config coreconfig.Reader 19 orgRepo organizations.OrganizationRepository 20 domainRepo api.DomainRepository 21 orgReq requirements.OrganizationRequirement 22 } 23 24 func init() { 25 commandregistry.Register(&UnsharePrivateDomain{}) 26 } 27 28 func (cmd *UnsharePrivateDomain) MetaData() commandregistry.CommandMetadata { 29 return commandregistry.CommandMetadata{ 30 Name: "unshare-private-domain", 31 Description: T("Unshare a private domain with an org"), 32 Usage: []string{ 33 T("CF_NAME unshare-private-domain ORG DOMAIN"), 34 }, 35 } 36 } 37 38 func (cmd *UnsharePrivateDomain) Requirements(requirementsFactory requirements.Factory, fc flags.FlagContext) ([]requirements.Requirement, error) { 39 if len(fc.Args()) != 2 { 40 cmd.ui.Failed(T("Incorrect Usage. Requires ORG and DOMAIN arguments\n\n") + commandregistry.Commands.CommandUsage("unshare-private-domain")) 41 return nil, fmt.Errorf("Incorrect usage: %d arguments of %d required", len(fc.Args()), 1) 42 } 43 44 cmd.orgReq = requirementsFactory.NewOrganizationRequirement(fc.Args()[0]) 45 46 reqs := []requirements.Requirement{ 47 requirementsFactory.NewLoginRequirement(), 48 cmd.orgReq, 49 } 50 51 return reqs, nil 52 } 53 54 func (cmd *UnsharePrivateDomain) SetDependency(deps commandregistry.Dependency, pluginCall bool) commandregistry.Command { 55 cmd.ui = deps.UI 56 cmd.config = deps.Config 57 cmd.orgRepo = deps.RepoLocator.GetOrganizationRepository() 58 cmd.domainRepo = deps.RepoLocator.GetDomainRepository() 59 return cmd 60 } 61 62 func (cmd *UnsharePrivateDomain) Execute(c flags.FlagContext) error { 63 org := cmd.orgReq.GetOrganization() 64 domainName := c.Args()[1] 65 domain, err := cmd.domainRepo.FindPrivateByName(domainName) 66 67 if err != nil { 68 return err 69 } 70 71 cmd.ui.Say(T("Unsharing domain {{.DomainName}} from org {{.OrgName}} as {{.Username}}...", 72 map[string]interface{}{ 73 "DomainName": terminal.EntityNameColor(domain.Name), 74 "OrgName": terminal.EntityNameColor(org.Name), 75 "Username": terminal.EntityNameColor(cmd.config.Username())})) 76 77 err = cmd.orgRepo.UnsharePrivateDomain(org.GUID, domain.GUID) 78 if err != nil { 79 return err 80 } 81 82 cmd.ui.Ok() 83 return nil 84 }