Skip to content

Commit

Permalink
main: allow version metadata to be set
Browse files Browse the repository at this point in the history
  • Loading branch information
radeksimko committed Jun 9, 2022
1 parent d6d711a commit ef9f28a
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions version.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package main

import (
"fmt"

goversion "github.com/hashicorp/go-version"
)

Expand All @@ -12,7 +10,10 @@ var version = "0.0.0"
// 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.
var prerelease = "dev"
var versionPrerelease = "dev"

// Version (build) metadata, such as homebrew
var versionMetadata = ""

func init() {
// Verify that the version is proper semantic version, which should always be the case.
Expand All @@ -24,8 +25,14 @@ func init() {

// VersionString returns the complete version string, including prerelease
func VersionString() string {
if prerelease != "" {
return fmt.Sprintf("%s-%s", version, prerelease)
v := version
if versionPrerelease != "" {
v += "-" + versionPrerelease
}
return version

if versionMetadata != "" {
v += "+" + versionMetadata
}

return v
}

0 comments on commit ef9f28a

Please sign in to comment.