github.com/loggregator/cli@v6.33.1-0.20180224010324-82334f081791+incompatible/cf/commands/spacequota/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/commandregistry" 8 "code.cloudfoundry.org/cli/cf/configuration/coreconfig" 9 "code.cloudfoundry.org/cli/cf/flags" 10 "code.cloudfoundry.org/cli/cf/formatters" 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 SpaceQuota struct { 17 ui terminal.UI 18 config coreconfig.Reader 19 spaceQuotaRepo spacequotas.SpaceQuotaRepository 20 } 21 22 func init() { 23 commandregistry.Register(&SpaceQuota{}) 24 } 25 26 func (cmd *SpaceQuota) MetaData() commandregistry.CommandMetadata { 27 return commandregistry.CommandMetadata{ 28 Name: "space-quota", 29 Description: T("Show space quota info"), 30 Usage: []string{ 31 T("CF_NAME space-quota SPACE_QUOTA_NAME"), 32 }, 33 } 34 } 35 36 func (cmd *SpaceQuota) Requirements(requirementsFactory requirements.Factory, fc flags.FlagContext) ([]requirements.Requirement, error) { 37 if len(fc.Args()) != 1 { 38 cmd.ui.Failed(T("Incorrect Usage. Requires an argument\n\n") + commandregistry.Commands.CommandUsage("space-quota")) 39 return nil, fmt.Errorf("Incorrect usage: %d arguments of %d required", len(fc.Args()), 1) 40 } 41 42 reqs := []requirements.Requirement{ 43 requirementsFactory.NewLoginRequirement(), 44 requirementsFactory.NewTargetedOrgRequirement(), 45 } 46 47 return reqs, nil 48 } 49 50 func (cmd *SpaceQuota) SetDependency(deps commandregistry.Dependency, pluginCall bool) commandregistry.Command { 51 cmd.ui = deps.UI 52 cmd.config = deps.Config 53 cmd.spaceQuotaRepo = deps.RepoLocator.GetSpaceQuotaRepository() 54 return cmd 55 } 56 57 func (cmd *SpaceQuota) Execute(c flags.FlagContext) error { 58 name := c.Args()[0] 59 60 cmd.ui.Say(T("Getting space quota {{.Quota}} info as {{.Username}}...", 61 map[string]interface{}{ 62 "Quota": terminal.EntityNameColor(name), 63 "Username": terminal.EntityNameColor(cmd.config.Username()), 64 })) 65 66 spaceQuota, err := cmd.spaceQuotaRepo.FindByName(name) 67 68 if err != nil { 69 return err 70 } 71 72 cmd.ui.Ok() 73 cmd.ui.Say("") 74 var megabytes string 75 76 table := cmd.ui.Table([]string{"", ""}) 77 table.Add(T("total memory limit"), formatters.ByteSize(spaceQuota.MemoryLimit*formatters.MEGABYTE)) 78 if spaceQuota.InstanceMemoryLimit == -1 { 79 megabytes = T("unlimited") 80 } else { 81 megabytes = formatters.ByteSize(spaceQuota.InstanceMemoryLimit * formatters.MEGABYTE) 82 } 83 84 table.Add(T("instance memory limit"), megabytes) 85 table.Add(T("routes"), fmt.Sprintf("%d", spaceQuota.RoutesLimit)) 86 table.Add(T("services"), T(spaceQuota.FormattedServicesLimit())) 87 table.Add(T("non basic services"), formatters.Allowed(spaceQuota.NonBasicServicesAllowed)) 88 table.Add(T("app instance limit"), T(spaceQuota.FormattedAppInstanceLimit())) 89 table.Add(T("reserved route ports"), T(spaceQuota.FormattedRoutePortsLimit())) 90 91 err = table.Print() 92 if err != nil { 93 return err 94 } 95 return nil 96 }