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