github.com/hernad/nomad@v1.6.112/command/acl_role_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/mitchellh/cli" 11 "github.com/posener/complete" 12 ) 13 14 // Ensure ACLRoleDeleteCommand satisfies the cli.Command interface. 15 var _ cli.Command = &ACLRoleDeleteCommand{} 16 17 // ACLRoleDeleteCommand implements cli.Command. 18 type ACLRoleDeleteCommand struct { 19 Meta 20 } 21 22 // Help satisfies the cli.Command Help function. 23 func (a *ACLRoleDeleteCommand) Help() string { 24 helpText := ` 25 Usage: nomad acl role delete <acl_role_id> 26 27 Delete is used to delete an existing ACL role. Use requires a management 28 token. 29 30 General Options: 31 32 ` + generalOptionsUsage(usageOptsDefault|usageOptsNoNamespace) 33 34 return strings.TrimSpace(helpText) 35 } 36 37 func (a *ACLRoleDeleteCommand) AutocompleteFlags() complete.Flags { 38 return mergeAutocompleteFlags(a.Meta.AutocompleteFlags(FlagSetClient), 39 complete.Flags{}) 40 } 41 42 func (a *ACLRoleDeleteCommand) AutocompleteArgs() complete.Predictor { return complete.PredictNothing } 43 44 // Synopsis satisfies the cli.Command Synopsis function. 45 func (a *ACLRoleDeleteCommand) Synopsis() string { return "Delete an existing ACL role" } 46 47 // Name returns the name of this command. 48 func (a *ACLRoleDeleteCommand) Name() string { return "acl role delete" } 49 50 // Run satisfies the cli.Command Run function. 51 func (a *ACLRoleDeleteCommand) Run(args []string) int { 52 53 flags := a.Meta.FlagSet(a.Name(), FlagSetClient) 54 flags.Usage = func() { a.Ui.Output(a.Help()) } 55 56 if err := flags.Parse(args); err != nil { 57 return 1 58 } 59 60 // Check that the last argument is the role ID to delete. 61 if len(flags.Args()) != 1 { 62 a.Ui.Error("This command takes one argument: <acl_role_id>") 63 a.Ui.Error(commandErrorText(a)) 64 return 1 65 } 66 67 aclRoleID := flags.Args()[0] 68 69 // Get the HTTP client. 70 client, err := a.Meta.Client() 71 if err != nil { 72 a.Ui.Error(fmt.Sprintf("Error initializing client: %s", err)) 73 return 1 74 } 75 76 // Delete the specified ACL role. 77 _, err = client.ACLRoles().Delete(aclRoleID, nil) 78 if err != nil { 79 a.Ui.Error(fmt.Sprintf("Error deleting ACL role: %s", err)) 80 return 1 81 } 82 83 // Give some feedback to indicate the deletion was successful. 84 a.Ui.Output(fmt.Sprintf("ACL role %s successfully deleted", aclRoleID)) 85 return 0 86 }