version.go

 1package version
 2
 3import "runtime/debug"
 4
 5// Build-time parameters set via -ldflags.
 6
 7var (
 8	Version = "devel"
 9	Commit  = "unknown"
10)
11
12// A user may install crush using `go install github.com/charmbracelet/crush@latest`.
13// without -ldflags, in which case the version above is unset. As a workaround
14// we use the embedded build version that *is* set when using `go install` (and
15// is only set for `go install` and not for `go build`).
16func init() {
17	info, ok := debug.ReadBuildInfo()
18	if !ok {
19		return
20	}
21	mainVersion := info.Main.Version
22	if mainVersion != "" && mainVersion != "(devel)" {
23		Version = mainVersion
24	}
25}