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