github.com/loggregator/cli@v6.33.1-0.20180224010324-82334f081791+incompatible/cf/commands/spacequota/unset_space_quota.go (about) 1 package spacequota 2 3 import ( 4 "fmt" 5 6 "code.cloudfoundry.org/cli/cf/api/spacequotas" 7 "code.cloudfoundry.org/cli/cf/api/spaces" 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 UnsetSpaceQuota struct { 17 ui terminal.UI 18 config coreconfig.Reader 19 quotaRepo spacequotas.SpaceQuotaRepository 20 spaceRepo spaces.SpaceRepository 21 } 22 23 func init() { 24 commandregistry.Register(&UnsetSpaceQuota{}) 25 } 26 27 func (cmd *UnsetSpaceQuota) MetaData() commandregistry.CommandMetadata { 28 return commandregistry.CommandMetadata{ 29 Name: "unset-space-quota", 30 Description: T("Unassign a quota from a space"), 31 Usage: []string{ 32 T("CF_NAME unset-space-quota SPACE QUOTA\n\n"), 33 }, 34 } 35 } 36 37 func (cmd *UnsetSpaceQuota) Requirements(requirementsFactory requirements.Factory, fc flags.FlagContext) ([]requirements.Requirement, error) { 38 if len(fc.Args()) != 2 { 39 cmd.ui.Failed(T("Incorrect Usage. Requires SPACE and QUOTA as arguments\n\n") + commandregistry.Commands.CommandUsage("unset-space-quota")) 40 return nil, fmt.Errorf("Incorrect usage: %d arguments of %d required", len(fc.Args()), 2) 41 } 42 43 reqs := []requirements.Requirement{ 44 requirementsFactory.NewLoginRequirement(), 45 requirementsFactory.NewTargetedOrgRequirement(), 46 } 47 48 return reqs, nil 49 } 50 51 func (cmd *UnsetSpaceQuota) SetDependency(deps commandregistry.Dependency, pluginCall bool) commandregistry.Command { 52 cmd.ui = deps.UI 53 cmd.config = deps.Config 54 cmd.spaceRepo = deps.RepoLocator.GetSpaceRepository() 55 cmd.quotaRepo = deps.RepoLocator.GetSpaceQuotaRepository() 56 return cmd 57 } 58 59 func (cmd *UnsetSpaceQuota) Execute(c flags.FlagContext) error { 60 spaceName := c.Args()[0] 61 quotaName := c.Args()[1] 62 63 space, err := cmd.spaceRepo.FindByName(spaceName) 64 if err != nil { 65 return err 66 } 67 68 quota, err := cmd.quotaRepo.FindByName(quotaName) 69 if err != nil { 70 return err 71 } 72 73 cmd.ui.Say(T("Unassigning space quota {{.QuotaName}} from space {{.SpaceName}} as {{.Username}}...", 74 map[string]interface{}{ 75 "QuotaName": terminal.EntityNameColor(quota.Name), 76 "SpaceName": terminal.EntityNameColor(space.Name), 77 "Username": terminal.EntityNameColor(cmd.config.Username())})) 78 79 err = cmd.quotaRepo.UnassignQuotaFromSpace(space.GUID, quota.GUID) 80 if err != nil { 81 return err 82 } 83 84 cmd.ui.Ok() 85 return nil 86 }