github.com/hernad/nomad@v1.6.112/command/acl_policy_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 ACLPolicyDeleteCommand struct { 14 Meta 15 } 16 17 func (c *ACLPolicyDeleteCommand) Help() string { 18 helpText := ` 19 Usage: nomad acl policy delete <name> 20 21 Delete is used to delete an existing ACL policy. 22 23 This command requires a management ACL token. 24 25 General Options: 26 27 ` + generalOptionsUsage(usageOptsDefault|usageOptsNoNamespace) 28 29 return strings.TrimSpace(helpText) 30 } 31 32 func (c *ACLPolicyDeleteCommand) AutocompleteFlags() complete.Flags { 33 return mergeAutocompleteFlags(c.Meta.AutocompleteFlags(FlagSetClient), 34 complete.Flags{}) 35 } 36 37 func (c *ACLPolicyDeleteCommand) AutocompleteArgs() complete.Predictor { 38 return complete.PredictNothing 39 } 40 41 func (c *ACLPolicyDeleteCommand) Synopsis() string { 42 return "Delete an existing ACL policy" 43 } 44 45 func (c *ACLPolicyDeleteCommand) Name() string { return "acl policy delete" } 46 47 func (c *ACLPolicyDeleteCommand) Run(args []string) int { 48 flags := c.Meta.FlagSet(c.Name(), FlagSetClient) 49 flags.Usage = func() { c.Ui.Output(c.Help()) } 50 if err := flags.Parse(args); err != nil { 51 return 1 52 } 53 54 // Check that we got exactly one argument 55 args = flags.Args() 56 if l := len(args); l != 1 { 57 c.Ui.Error("This command takes one argument: <name>") 58 c.Ui.Error(commandErrorText(c)) 59 return 1 60 } 61 62 // Get the policy name 63 policyName := args[0] 64 65 // Get the HTTP client 66 client, err := c.Meta.Client() 67 if err != nil { 68 c.Ui.Error(fmt.Sprintf("Error initializing client: %s", err)) 69 return 1 70 } 71 72 // Delete the policy 73 _, err = client.ACLPolicies().Delete(policyName, nil) 74 if err != nil { 75 c.Ui.Error(fmt.Sprintf("Error deleting ACL policy: %s", err)) 76 return 1 77 } 78 79 c.Ui.Output(fmt.Sprintf("Successfully deleted %s policy!", 80 policyName)) 81 return 0 82 }