Skip to content

Commit

Permalink
internal/witcli: add Version helper
Browse files Browse the repository at this point in the history
  • Loading branch information
ydnar committed Oct 30, 2024
1 parent a50b64c commit 12ff7d1
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions internal/witcli/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package witcli

import (
"runtime/debug"
"sync"
)

// Version returns the version string of this module.
func Version() string {
return versionString()
}

var versionString = sync.OnceValue(func() string {
build, ok := debug.ReadBuildInfo()
if !ok {
return "(none)"
}
version := build.Main.Version
var revision string
for _, s := range build.Settings {
switch s.Key {
case "vcs.revision":
revision = s.Value
}
}
if version == "" {
version = "(none)"
}
versionString := version
if revision != "" {
versionString += " (" + revision + ")"
}
return versionString
})

0 comments on commit 12ff7d1

Please sign in to comment.