github.com/loafoe/cli@v7.1.0+incompatible/command/v7/delete_org_quota_command.go (about)

     1  package v7
     2  
     3  import (
     4  	"code.cloudfoundry.org/cli/actor/actionerror"
     5  	"code.cloudfoundry.org/cli/command/flag"
     6  )
     7  
     8  type DeleteOrgQuotaCommand struct {
     9  	BaseCommand
    10  
    11  	RequiredArgs    flag.Quota  `positional-args:"yes"`
    12  	Force           bool        `long:"force" short:"f" description:"Force deletion without confirmation"`
    13  	usage           interface{} `usage:"CF_NAME delete-org-quota QUOTA [-f]"`
    14  	relatedCommands interface{} `related_commands:"org-quotas"`
    15  }
    16  
    17  func (cmd DeleteOrgQuotaCommand) Execute(args []string) error {
    18  	err := cmd.SharedActor.CheckTarget(false, false)
    19  	if err != nil {
    20  		return err
    21  	}
    22  
    23  	user, err := cmd.Config.CurrentUser()
    24  	if err != nil {
    25  		return err
    26  	}
    27  
    28  	orgQuotaName := cmd.RequiredArgs.Quota
    29  
    30  	if !cmd.Force {
    31  		promptMessage := "Really delete the org quota {{.QuotaName}}?"
    32  		confirmedDelete, promptErr := cmd.UI.DisplayBoolPrompt(false, promptMessage, map[string]interface{}{
    33  			"QuotaName": orgQuotaName,
    34  		})
    35  
    36  		if promptErr != nil {
    37  			return promptErr
    38  		}
    39  
    40  		if !confirmedDelete {
    41  			cmd.UI.DisplayText("Organization quota '{{.QuotaName}}' has not been deleted.", map[string]interface{}{"QuotaName": orgQuotaName})
    42  			return nil
    43  		}
    44  	}
    45  
    46  	cmd.UI.DisplayTextWithFlavor("Deleting org quota {{.QuotaName}} as {{.User}}...",
    47  		map[string]interface{}{
    48  			"User":      user.Name,
    49  			"QuotaName": orgQuotaName,
    50  		})
    51  
    52  	warnings, err := cmd.Actor.DeleteOrganizationQuota(orgQuotaName)
    53  
    54  	cmd.UI.DisplayWarnings(warnings)
    55  
    56  	if err != nil {
    57  		switch err.(type) {
    58  		case actionerror.OrganizationQuotaNotFoundForNameError:
    59  			cmd.UI.DisplayWarning(err.Error())
    60  		default:
    61  			return err
    62  		}
    63  	}
    64  
    65  	cmd.UI.DisplayOK()
    66  
    67  	return nil
    68  }