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