github.com/hernad/nomad@v1.6.112/command/namespace_delete.go (about) 1 // Copyright (c) HashiCorp, Inc. 2 // SPDX-License-Identifier: MPL-2.0 3 4 package command 5 6 import ( 7 "fmt" 8 "strings" 9 10 "github.com/posener/complete" 11 ) 12 13 type NamespaceDeleteCommand struct { 14 Meta 15 } 16 17 func (c *NamespaceDeleteCommand) Help() string { 18 helpText := ` 19 Usage: nomad namespace delete [options] <namespace> 20 21 Delete is used to remove a namespace. 22 23 If ACLs are enabled, this command requires a management ACL token. 24 25 You cannot delete a namespace that has non-terminal jobs. In federated 26 clusters, you cannot delete a namespace that has non-terminal jobs in any of 27 the federated regions. 28 29 General Options: 30 31 ` + generalOptionsUsage(usageOptsDefault|usageOptsNoNamespace) 32 33 return strings.TrimSpace(helpText) 34 } 35 36 func (c *NamespaceDeleteCommand) AutocompleteFlags() complete.Flags { 37 return c.Meta.AutocompleteFlags(FlagSetClient) 38 } 39 40 func (c *NamespaceDeleteCommand) AutocompleteArgs() complete.Predictor { 41 filter := map[string]struct{}{"default": {}} 42 return NamespacePredictor(c.Meta.Client, filter) 43 } 44 45 func (c *NamespaceDeleteCommand) Synopsis() string { 46 return "Delete a namespace" 47 } 48 49 func (c *NamespaceDeleteCommand) Name() string { return "namespace delete" } 50 51 func (c *NamespaceDeleteCommand) Run(args []string) int { 52 flags := c.Meta.FlagSet(c.Name(), FlagSetClient) 53 flags.Usage = func() { c.Ui.Output(c.Help()) } 54 55 if err := flags.Parse(args); err != nil { 56 return 1 57 } 58 59 // Check that we got one argument 60 args = flags.Args() 61 if l := len(args); l != 1 { 62 c.Ui.Error("This command takes one argument: <namespace>") 63 c.Ui.Error(commandErrorText(c)) 64 return 1 65 } 66 67 namespace := args[0] 68 69 // Get the HTTP client 70 client, err := c.Meta.Client() 71 if err != nil { 72 c.Ui.Error(fmt.Sprintf("Error initializing client: %s", err)) 73 return 1 74 } 75 76 _, err = client.Namespaces().Delete(namespace, nil) 77 if err != nil { 78 c.Ui.Error(fmt.Sprintf("Error deleting namespace: %s", err)) 79 return 1 80 } 81 82 c.Ui.Output(fmt.Sprintf("Successfully deleted namespace %q!", namespace)) 83 return 0 84 }