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.
|
2022-05-11 21:42:53 +00:00
|
|
|
Version = "1.3.1"
|
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.
|
2022-04-07 22:48:02 +00:00
|
|
|
VersionPrerelease = "dev"
|
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 {
|
2020-12-09 19:05:18 +00:00
|
|
|
version := c.Version
|
2017-08-16 22:42:15 +00:00
|
|
|
|
|
|
|
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()
|
|
|
|
}
|