2017-10-13 21:36:02 +00:00
|
|
|
package command
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/posener/complete"
|
|
|
|
)
|
|
|
|
|
|
|
|
type QuotaDeleteCommand struct {
|
|
|
|
Meta
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *QuotaDeleteCommand) Help() string {
|
|
|
|
helpText := `
|
|
|
|
Usage: nomad quota delete [options] <quota>
|
|
|
|
|
2017-10-13 21:02:30 +00:00
|
|
|
Delete is used to delete an existing quota specification.
|
2017-10-13 21:36:02 +00:00
|
|
|
|
|
|
|
General Options:
|
|
|
|
|
|
|
|
` + generalOptionsUsage()
|
|
|
|
|
|
|
|
return strings.TrimSpace(helpText)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *QuotaDeleteCommand) AutocompleteFlags() complete.Flags {
|
|
|
|
return c.Meta.AutocompleteFlags(FlagSetClient)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *QuotaDeleteCommand) AutocompleteArgs() complete.Predictor {
|
|
|
|
return QuotaPredictor(c.Meta.Client)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *QuotaDeleteCommand) Synopsis() string {
|
|
|
|
return "Delete a quota specification"
|
|
|
|
}
|
|
|
|
|
2018-04-18 16:02:11 +00:00
|
|
|
func (c *QuotaDeleteCommand) Name() string { return "quota delete" }
|
|
|
|
|
2017-10-13 21:36:02 +00:00
|
|
|
func (c *QuotaDeleteCommand) Run(args []string) int {
|
2018-04-18 16:02:11 +00:00
|
|
|
flags := c.Meta.FlagSet(c.Name(), FlagSetClient)
|
2017-10-13 21:36:02 +00:00
|
|
|
flags.Usage = func() { c.Ui.Output(c.Help()) }
|
|
|
|
|
|
|
|
if err := flags.Parse(args); err != nil {
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check that we got one argument
|
|
|
|
args = flags.Args()
|
|
|
|
if l := len(args); l != 1 {
|
2018-04-18 17:55:51 +00:00
|
|
|
c.Ui.Error("This command takes one argument: <quota>")
|
2018-04-18 16:02:11 +00:00
|
|
|
c.Ui.Error(commandErrorText(c))
|
2017-10-13 21:36:02 +00:00
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
name := args[0]
|
|
|
|
|
|
|
|
// Get the HTTP client
|
|
|
|
client, err := c.Meta.Client()
|
|
|
|
if err != nil {
|
|
|
|
c.Ui.Error(fmt.Sprintf("Error initializing client: %s", err))
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err = client.Quotas().Delete(name, nil)
|
|
|
|
if err != nil {
|
|
|
|
c.Ui.Error(fmt.Sprintf("Error deleting quota: %s", err))
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
c.Ui.Output(fmt.Sprintf("Successfully deleted quota %q!", name))
|
|
|
|
return 0
|
|
|
|
}
|