github.com/sleungcy/cli@v7.1.0+incompatible/command/v7/space_quotas_command.go (about)

     1  package v7
     2  
     3  import (
     4  	"code.cloudfoundry.org/cli/command/v7/shared"
     5  	"code.cloudfoundry.org/cli/resources"
     6  )
     7  
     8  type SpaceQuotasCommand struct {
     9  	BaseCommand
    10  
    11  	usage           interface{} `usage:"CF_NAME space-quotas"`
    12  	relatedCommands interface{} `related_commands:"space-quota, set-space-quota"`
    13  }
    14  
    15  func (cmd SpaceQuotasCommand) Execute(args []string) error {
    16  	err := cmd.SharedActor.CheckTarget(true, false)
    17  	if err != nil {
    18  		return err
    19  	}
    20  
    21  	user, err := cmd.Config.CurrentUser()
    22  	if err != nil {
    23  		return err
    24  	}
    25  
    26  	cmd.UI.DisplayTextWithFlavor("Getting space quotas for org {{.OrgName}} as {{.Username}}...", map[string]interface{}{
    27  		"OrgName":  cmd.Config.TargetedOrganizationName(),
    28  		"Username": user.Name,
    29  	})
    30  	cmd.UI.DisplayNewline()
    31  
    32  	orgQuotas, warnings, err := cmd.Actor.GetSpaceQuotasByOrgGUID(cmd.Config.TargetedOrganization().GUID)
    33  	cmd.UI.DisplayWarnings(warnings)
    34  	if err != nil {
    35  		return err
    36  	}
    37  
    38  	var quotas []resources.Quota
    39  	for _, orgQuota := range orgQuotas {
    40  		quotas = append(quotas, resources.Quota(orgQuota.Quota))
    41  	}
    42  
    43  	quotaDisplayer := shared.NewQuotaDisplayer(cmd.UI)
    44  	quotaDisplayer.DisplayQuotasTable(quotas, "No space quotas found.")
    45  
    46  	return nil
    47  }