version.go 595 B

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