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