version.go 691 B

12345678910111213141516171819202122232425
  1. package version
  2. import "runtime/debug"
  3. // Build-time parameters set via -ldflags
  4. var Version = "unknown"
  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. // < go v1.18
  13. return
  14. }
  15. mainVersion := info.Main.Version
  16. if mainVersion == "" || mainVersion == "(devel)" {
  17. // bin not built using `go install`
  18. return
  19. }
  20. // bin built using `go install`
  21. Version = mainVersion
  22. }