github.com/Ilhicas/nomad@v1.0.4-0.20210304152020-e86851182bc3/command/quota_delete.go (about)

     1  package command
     2  
     3  import (
     4  	"fmt"
     5  	"strings"
     6  
     7  	"github.com/posener/complete"
     8  )
     9  
    10  type QuotaDeleteCommand struct {
    11  	Meta
    12  }
    13  
    14  func (c *QuotaDeleteCommand) Help() string {
    15  	helpText := `
    16  Usage: nomad quota delete [options] <quota>
    17  
    18    Delete is used to delete an existing quota specification.
    19  
    20    If ACLs are enabled, this command requires a token with the 'quota:write'
    21    capability.
    22  
    23  General Options:
    24  
    25    ` + generalOptionsUsage(usageOptsDefault)
    26  
    27  	return strings.TrimSpace(helpText)
    28  }
    29  
    30  func (c *QuotaDeleteCommand) AutocompleteFlags() complete.Flags {
    31  	return c.Meta.AutocompleteFlags(FlagSetClient)
    32  }
    33  
    34  func (c *QuotaDeleteCommand) AutocompleteArgs() complete.Predictor {
    35  	return QuotaPredictor(c.Meta.Client)
    36  }
    37  
    38  func (c *QuotaDeleteCommand) Synopsis() string {
    39  	return "Delete a quota specification"
    40  }
    41  
    42  func (c *QuotaDeleteCommand) Name() string { return "quota delete" }
    43  
    44  func (c *QuotaDeleteCommand) Run(args []string) int {
    45  	flags := c.Meta.FlagSet(c.Name(), FlagSetClient)
    46  	flags.Usage = func() { c.Ui.Output(c.Help()) }
    47  
    48  	if err := flags.Parse(args); err != nil {
    49  		return 1
    50  	}
    51  
    52  	// Check that we got one argument
    53  	args = flags.Args()
    54  	if l := len(args); l != 1 {
    55  		c.Ui.Error("This command takes one argument: <quota>")
    56  		c.Ui.Error(commandErrorText(c))
    57  		return 1
    58  	}
    59  
    60  	name := args[0]
    61  
    62  	// Get the HTTP client
    63  	client, err := c.Meta.Client()
    64  	if err != nil {
    65  		c.Ui.Error(fmt.Sprintf("Error initializing client: %s", err))
    66  		return 1
    67  	}
    68  
    69  	_, err = client.Quotas().Delete(name, nil)
    70  	if err != nil {
    71  		c.Ui.Error(fmt.Sprintf("Error deleting quota: %s", err))
    72  		return 1
    73  	}
    74  
    75  	c.Ui.Output(fmt.Sprintf("Successfully deleted quota %q!", name))
    76  	return 0
    77  }