github.com/Ilhicas/nomad@v1.0.4-0.20210304152020-e86851182bc3/command/license_get.go (about) 1 package command 2 3 import ( 4 "fmt" 5 ) 6 7 type LicenseGetCommand struct { 8 Meta 9 } 10 11 func (c *LicenseGetCommand) Help() string { 12 helpText := ` 13 Usage: nomad license get [options] 14 15 Gets a new license in Servers and Clients 16 17 When ACLs are enabled, this command requires a token with the 18 'operator:read' capability. 19 20 General Options: 21 22 ` + generalOptionsUsage(usageOptsDefault|usageOptsNoNamespace) 23 24 return helpText 25 } 26 27 func (c *LicenseGetCommand) Synopsis() string { 28 return "Retrieve the current Nomad Enterprise License" 29 } 30 31 func (c *LicenseGetCommand) Name() string { return "license get" } 32 33 func (c *LicenseGetCommand) Run(args []string) int { 34 flags := c.Meta.FlagSet(c.Name(), FlagSetClient) 35 flags.Usage = func() { c.Ui.Output(c.Help()) } 36 37 if err := flags.Parse(args); err != nil { 38 c.Ui.Error(fmt.Sprintf("Error parsing flags: %s", err)) 39 return 1 40 } 41 42 client, err := c.Meta.Client() 43 if err != nil { 44 c.Ui.Error(fmt.Sprintf("Error initializing client: %s", err)) 45 return 1 46 } 47 48 resp, _, err := client.Operator().LicenseGet(nil) 49 if err != nil { 50 c.Ui.Error(fmt.Sprintf("Error getting license: %v", err)) 51 return 1 52 } 53 54 return OutputLicenseReply(c.Ui, resp) 55 }