2017-08-16 22:42:15 +00:00
|
|
|
package version
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
// The git commit that was compiled. This will be filled in by the compiler.
|
|
|
|
GitCommit string
|
|
|
|
GitDescribe string
|
|
|
|
|
|
|
|
// The main version number that is being run at the moment.
|
2017-12-20 01:10:52 +00:00
|
|
|
Version = "0.8.0"
|
2017-08-16 22:42:15 +00:00
|
|
|
|
|
|
|
// A pre-release marker for the version. If this is "" (empty string)
|
|
|
|
// then it means that it is a final release. Otherwise, this is a pre-release
|
|
|
|
// such as "dev" (in development), "beta", "rc1", etc.
|
2018-03-30 23:12:38 +00:00
|
|
|
VersionPrerelease = "rc1"
|
2017-08-16 22:42:15 +00:00
|
|
|
|
|
|
|
// VersionMetadata is metadata further describing the build type.
|
|
|
|
VersionMetadata = ""
|
|
|
|
)
|
|
|
|
|
|
|
|
// VersionInfo
|
|
|
|
type VersionInfo struct {
|
|
|
|
Revision string
|
|
|
|
Version string
|
|
|
|
VersionPrerelease string
|
|
|
|
VersionMetadata string
|
|
|
|
}
|
|
|
|
|
|
|
|
func GetVersion() *VersionInfo {
|
|
|
|
ver := Version
|
|
|
|
rel := VersionPrerelease
|
|
|
|
md := VersionMetadata
|
|
|
|
if GitDescribe != "" {
|
|
|
|
ver = GitDescribe
|
|
|
|
}
|
|
|
|
if GitDescribe == "" && rel == "" && VersionPrerelease != "" {
|
|
|
|
rel = "dev"
|
|
|
|
}
|
|
|
|
|
|
|
|
return &VersionInfo{
|
|
|
|
Revision: GitCommit,
|
|
|
|
Version: ver,
|
|
|
|
VersionPrerelease: rel,
|
|
|
|
VersionMetadata: md,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *VersionInfo) VersionNumber() string {
|
|
|
|
version := fmt.Sprintf("%s", c.Version)
|
|
|
|
|
|
|
|
if c.VersionPrerelease != "" {
|
|
|
|
version = fmt.Sprintf("%s-%s", version, c.VersionPrerelease)
|
|
|
|
}
|
|
|
|
|
|
|
|
if c.VersionMetadata != "" {
|
|
|
|
version = fmt.Sprintf("%s+%s", version, c.VersionMetadata)
|
|
|
|
}
|
|
|
|
|
|
|
|
return version
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *VersionInfo) FullVersionNumber(rev bool) string {
|
|
|
|
var versionString bytes.Buffer
|
|
|
|
|
|
|
|
fmt.Fprintf(&versionString, "Nomad v%s", c.Version)
|
|
|
|
if c.VersionPrerelease != "" {
|
|
|
|
fmt.Fprintf(&versionString, "-%s", c.VersionPrerelease)
|
|
|
|
}
|
|
|
|
|
|
|
|
if c.VersionMetadata != "" {
|
|
|
|
fmt.Fprintf(&versionString, "+%s", c.VersionMetadata)
|
|
|
|
}
|
|
|
|
|
|
|
|
if rev && c.Revision != "" {
|
|
|
|
fmt.Fprintf(&versionString, " (%s)", c.Revision)
|
|
|
|
}
|
|
|
|
|
|
|
|
return versionString.String()
|
|
|
|
}
|