github.com/mattyr/nomad@v0.3.3-0.20160919021406-3485a065154a/command/version.go (about)

     1  package command
     2  
     3  import (
     4  	"bytes"
     5  	"fmt"
     6  
     7  	"github.com/mitchellh/cli"
     8  )
     9  
    10  // VersionCommand is a Command implementation prints the version.
    11  type VersionCommand struct {
    12  	Revision          string
    13  	Version           string
    14  	VersionPrerelease string
    15  	Ui                cli.Ui
    16  }
    17  
    18  func (c *VersionCommand) Help() string {
    19  	return ""
    20  }
    21  
    22  func (c *VersionCommand) Run(_ []string) int {
    23  	var versionString bytes.Buffer
    24  
    25  	fmt.Fprintf(&versionString, "Nomad v%s", c.Version)
    26  	if c.VersionPrerelease != "" {
    27  		fmt.Fprintf(&versionString, "-%s", c.VersionPrerelease)
    28  
    29  		if c.Revision != "" {
    30  			fmt.Fprintf(&versionString, " (%s)", c.Revision)
    31  		}
    32  	}
    33  
    34  	c.Ui.Output(versionString.String())
    35  	return 0
    36  }
    37  
    38  func (c *VersionCommand) Synopsis() string {
    39  	return "Prints the Nomad version"
    40  }