Move build-time version info to shared `build` package
The CLI had the version injected at build time. This moves the
build-time-injected variables into their own package so that all
executables can simply import this package and use the appropriate build
flags to have version info injected rather than replicating the
functionality themselves.
@@ -3,37 +3,27 @@ package version
import (
"fmt"
+ "github.com/dapperlabs/flow-go/build"
"github.com/spf13/cobra"
)
-// Default value for build-time-injected version strings.
-const unknown = "undefined"
-
-var (
- // The Git commit hash, injected at build time
- commit = unknown
- // The semver version string, injected at build time
- version = unknown
-)
-
var Cmd = &cobra.Command{
Use: "version",
Short: "View version and commit information",
Run: func(cmd *cobra.Command, args []string) {
+ semver := build.Semver()
+ commit := build.Commit()
+
// Print version/commit strings if they are known
- if isKnown(version) {
- fmt.Printf("Version: %s\n", version)
+ if build.IsDefined(semver) {
+ fmt.Printf("Version: %s\n", semver)
}
- if isKnown(commit) {
+ if build.IsDefined(commit) {
fmt.Printf("Commit: %s\n", commit)
}
// If no version info is known print a message to indicate this.
- if !isKnown(version) && !isKnown(commit) {
+ if !build.IsDefined(semver) && !build.IsDefined(commit) {
fmt.Printf("Version information unknown!\n")
}
},
}
-
-func isKnown(version string) bool {
- return version != unknown && len(version) > 0
-}
