github.com/DerekStrickland/consul@v1.4.5/command/version/version.go (about)

     1  package version
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/hashicorp/consul/agent/config"
     7  	"github.com/hashicorp/consul/agent/consul"
     8  	"github.com/mitchellh/cli"
     9  )
    10  
    11  func New(ui cli.Ui, version string) *cmd {
    12  	return &cmd{UI: ui, version: version}
    13  }
    14  
    15  type cmd struct {
    16  	UI      cli.Ui
    17  	version string
    18  }
    19  
    20  func (c *cmd) Run(_ []string) int {
    21  	c.UI.Output(fmt.Sprintf("Consul %s", c.version))
    22  
    23  	rpcProtocol, err := config.DefaultRPCProtocol()
    24  	if err != nil {
    25  		c.UI.Error(err.Error())
    26  		return 2
    27  	}
    28  	var supplement string
    29  	if rpcProtocol < consul.ProtocolVersionMax {
    30  		supplement = fmt.Sprintf(" (agent will automatically use protocol >%d when speaking to compatible agents)",
    31  			rpcProtocol)
    32  	}
    33  	c.UI.Output(fmt.Sprintf("Protocol %d spoken by default, understands %d to %d%s",
    34  		rpcProtocol, consul.ProtocolVersionMin, consul.ProtocolVersionMax, supplement))
    35  
    36  	return 0
    37  }
    38  
    39  func (c *cmd) Synopsis() string {
    40  	return "Prints the Consul version"
    41  }
    42  
    43  func (c *cmd) Help() string {
    44  	return ""
    45  }