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