github.com/hhrutter/nomad@v0.6.0-rc2.0.20170723054333-80c4b03f0705/version.go (about)

     1  package main
     2  
     3  import (
     4  	"bytes"
     5  	"fmt"
     6  )
     7  
     8  // The git commit that was compiled. This will be filled in by the compiler.
     9  var GitCommit string
    10  var GitDescribe string
    11  
    12  // The main version number that is being run at the moment.
    13  const Version = "0.6.0"
    14  
    15  // A pre-release marker for the version. If this is "" (empty string)
    16  // then it means that it is a final release. Otherwise, this is a pre-release
    17  // such as "dev" (in development), "beta", "rc1", etc.
    18  const VersionPrerelease = "rc2"
    19  
    20  // GetVersionParts returns the Nomad version strings. Printing of the Nomad
    21  // version should be used in conjunction with the PrettyVersion method.
    22  func GetVersionParts() (rev, ver, rel string) {
    23  	ver = Version
    24  	rel = VersionPrerelease
    25  	if GitDescribe != "" {
    26  		ver = GitDescribe
    27  		// Trim off a leading 'v', we append it anyways.
    28  		if ver[0] == 'v' {
    29  			ver = ver[1:]
    30  		}
    31  	}
    32  	if GitDescribe == "" && rel == "" && VersionPrerelease != "" {
    33  		rel = "dev"
    34  	}
    35  
    36  	return GitCommit, ver, rel
    37  }
    38  
    39  // PrettyVersion takes the version parts and formats it in a human readable
    40  // string.
    41  func PrettyVersion(revision, version, versionPrerelease string) string {
    42  	var versionString bytes.Buffer
    43  
    44  	fmt.Fprintf(&versionString, "Nomad v%s", version)
    45  	if versionPrerelease != "" {
    46  		fmt.Fprintf(&versionString, "-%s", versionPrerelease)
    47  
    48  		if revision != "" {
    49  			fmt.Fprintf(&versionString, " (%s)", revision)
    50  		}
    51  	}
    52  
    53  	return versionString.String()
    54  }