github.com/smithx10/nomad@v0.9.1-rc1/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  General Options:
    21  
    22    ` + generalOptionsUsage()
    23  
    24  	return strings.TrimSpace(helpText)
    25  }
    26  
    27  func (c *QuotaDeleteCommand) AutocompleteFlags() complete.Flags {
    28  	return c.Meta.AutocompleteFlags(FlagSetClient)
    29  }
    30  
    31  func (c *QuotaDeleteCommand) AutocompleteArgs() complete.Predictor {
    32  	return QuotaPredictor(c.Meta.Client)
    33  }
    34  
    35  func (c *QuotaDeleteCommand) Synopsis() string {
    36  	return "Delete a quota specification"
    37  }
    38  
    39  func (c *QuotaDeleteCommand) Name() string { return "quota delete" }
    40  
    41  func (c *QuotaDeleteCommand) Run(args []string) int {
    42  	flags := c.Meta.FlagSet(c.Name(), FlagSetClient)
    43  	flags.Usage = func() { c.Ui.Output(c.Help()) }
    44  
    45  	if err := flags.Parse(args); err != nil {
    46  		return 1
    47  	}
    48  
    49  	// Check that we got one argument
    50  	args = flags.Args()
    51  	if l := len(args); l != 1 {
    52  		c.Ui.Error("This command takes one argument: <quota>")
    53  		c.Ui.Error(commandErrorText(c))
    54  		return 1
    55  	}
    56  
    57  	name := args[0]
    58  
    59  	// Get the HTTP client
    60  	client, err := c.Meta.Client()
    61  	if err != nil {
    62  		c.Ui.Error(fmt.Sprintf("Error initializing client: %s", err))
    63  		return 1
    64  	}
    65  
    66  	_, err = client.Quotas().Delete(name, nil)
    67  	if err != nil {
    68  		c.Ui.Error(fmt.Sprintf("Error deleting quota: %s", err))
    69  		return 1
    70  	}
    71  
    72  	c.Ui.Output(fmt.Sprintf("Successfully deleted quota %q!", name))
    73  	return 0
    74  }