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