github.com/aminovpavel/nomad@v0.11.8/command/acl_policy_info.go (about) 1 package command 2 3 import ( 4 "fmt" 5 "strings" 6 7 "github.com/posener/complete" 8 ) 9 10 type ACLPolicyInfoCommand struct { 11 Meta 12 } 13 14 func (c *ACLPolicyInfoCommand) Help() string { 15 helpText := ` 16 Usage: nomad acl policy info <name> 17 18 Info is used to fetch information on an existing ACL policy. 19 20 General Options: 21 22 ` + generalOptionsUsage() 23 24 return strings.TrimSpace(helpText) 25 } 26 27 func (c *ACLPolicyInfoCommand) AutocompleteFlags() complete.Flags { 28 return mergeAutocompleteFlags(c.Meta.AutocompleteFlags(FlagSetClient), 29 complete.Flags{}) 30 } 31 32 func (c *ACLPolicyInfoCommand) AutocompleteArgs() complete.Predictor { 33 return complete.PredictNothing 34 } 35 36 func (c *ACLPolicyInfoCommand) Synopsis() string { 37 return "Fetch info on an existing ACL policy" 38 } 39 40 func (c *ACLPolicyInfoCommand) Name() string { return "acl policy info" } 41 42 func (c *ACLPolicyInfoCommand) 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 got exactly one argument 50 args = flags.Args() 51 if l := len(args); l != 1 { 52 c.Ui.Error("This command takes one argument: <name>") 53 c.Ui.Error(commandErrorText(c)) 54 return 1 55 } 56 57 // Get the policy name 58 policyName := args[0] 59 60 // Get the HTTP client 61 client, err := c.Meta.Client() 62 if err != nil { 63 c.Ui.Error(fmt.Sprintf("Error initializing client: %s", err)) 64 return 1 65 } 66 67 // Fetch info on the policy 68 policy, _, err := client.ACLPolicies().Info(policyName, nil) 69 if err != nil { 70 c.Ui.Error(fmt.Sprintf("Error fetching info on ACL policy: %s", err)) 71 return 1 72 } 73 74 c.Ui.Output(formatKVPolicy(policy)) 75 return 0 76 }