github.com/djenriquez/nomad-1@v0.8.1/command/acl_token_delete.go (about) 1 package command 2 3 import ( 4 "fmt" 5 "strings" 6 7 "github.com/posener/complete" 8 ) 9 10 type ACLTokenDeleteCommand struct { 11 Meta 12 } 13 14 func (c *ACLTokenDeleteCommand) Help() string { 15 helpText := ` 16 Usage: nomad acl token delete <token_accessor_id> 17 18 Delete is used to delete an existing ACL token. Requires a management token. 19 20 General Options: 21 22 ` + generalOptionsUsage() 23 24 return strings.TrimSpace(helpText) 25 } 26 27 func (c *ACLTokenDeleteCommand) AutocompleteFlags() complete.Flags { 28 return mergeAutocompleteFlags(c.Meta.AutocompleteFlags(FlagSetClient), 29 complete.Flags{}) 30 } 31 32 func (c *ACLTokenDeleteCommand) AutocompleteArgs() complete.Predictor { 33 return complete.PredictNothing 34 } 35 36 func (c *ACLTokenDeleteCommand) Synopsis() string { 37 return "Delete an existing ACL token" 38 } 39 40 func (c *ACLTokenDeleteCommand) Run(args []string) int { 41 flags := c.Meta.FlagSet("acl token delete", FlagSetClient) 42 flags.Usage = func() { c.Ui.Output(c.Help()) } 43 44 if err := flags.Parse(args); err != nil { 45 return 1 46 } 47 48 // Check that the last argument is the token to delete. Return error if no 49 // such token was provided. 50 args = flags.Args() 51 if l := len(args); l != 1 { 52 c.Ui.Error(c.Help()) 53 return 1 54 } 55 56 tokenAccessorID := args[0] 57 58 // Get the HTTP client 59 client, err := c.Meta.Client() 60 if err != nil { 61 c.Ui.Error(fmt.Sprintf("Error initializing client: %s", err)) 62 return 1 63 } 64 65 // Delete the specified token 66 _, err = client.ACLTokens().Delete(tokenAccessorID, nil) 67 if err != nil { 68 c.Ui.Error(fmt.Sprintf("Error deleting token: %s", err)) 69 return 1 70 } 71 72 // Format the output 73 c.Ui.Output(fmt.Sprintf("Token %s successfully deleted", tokenAccessorID)) 74 return 0 75 }