version.go 622 B

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