github.com/hernad/nomad@v1.6.112/command/license_get.go (about)

     1  // Copyright (c) HashiCorp, Inc.
     2  // SPDX-License-Identifier: MPL-2.0
     3  
     4  package command
     5  
     6  import (
     7  	"fmt"
     8  
     9  	"github.com/hernad/nomad/api"
    10  	"github.com/posener/complete"
    11  )
    12  
    13  type LicenseGetCommand struct {
    14  	Meta
    15  }
    16  
    17  func (c *LicenseGetCommand) Help() string {
    18  	helpText := `
    19  Usage: nomad license get [options]
    20  
    21    Gets the license loaded by the server. The command is not forwarded to the
    22    Nomad leader, and will return the license from the specific server being
    23    contacted.
    24  
    25    When ACLs are enabled, this command requires a token with the
    26    'operator:read' capability.
    27  
    28  General Options:
    29  
    30    ` + generalOptionsUsage(usageOptsDefault|usageOptsNoNamespace)
    31  
    32  	return helpText
    33  }
    34  
    35  func (c *LicenseGetCommand) AutocompleteFlags() complete.Flags {
    36  	return complete.Flags{}
    37  }
    38  
    39  func (c *LicenseGetCommand) AutocompleteArgs() complete.Predictor {
    40  	return complete.PredictNothing
    41  }
    42  
    43  func (c *LicenseGetCommand) Synopsis() string {
    44  	return "Retrieve the current Nomad Enterprise License"
    45  }
    46  
    47  func (c *LicenseGetCommand) Name() string { return "license get" }
    48  
    49  func (c *LicenseGetCommand) Run(args []string) int {
    50  	flags := c.Meta.FlagSet(c.Name(), FlagSetClient)
    51  	flags.Usage = func() { c.Ui.Output(c.Help()) }
    52  
    53  	if err := flags.Parse(args); err != nil {
    54  		c.Ui.Error(fmt.Sprintf("Error parsing flags: %s", err))
    55  		return 1
    56  	}
    57  
    58  	client, err := c.Meta.Client()
    59  	if err != nil {
    60  		c.Ui.Error(fmt.Sprintf("Error initializing client: %s", err))
    61  		return 1
    62  	}
    63  
    64  	resp, _, err := client.Operator().LicenseGet(&api.QueryOptions{})
    65  	if err != nil {
    66  		c.Ui.Error(fmt.Sprintf("Error getting license: %v", err))
    67  		return 1
    68  	}
    69  
    70  	return OutputLicenseReply(c.Ui, resp)
    71  }