diff --git a/Makefile b/Makefile index fe0aec9..2288cb6 100644 --- a/Makefile +++ b/Makefile @@ -5,13 +5,12 @@ PREFIX=/usr/local BINDIR=$(PREFIX)/bin MANDIR=$(PREFIX)/share/man GO=go -LDFLAGS=-X "github.com/bouncepaw/mycorrhiza/version.taggedRelease=$$(git describe --tags --abbrev=0)" all: mycorrhiza mycorrhiza: $(GO) generate $(GOFLAGS) - CGO_ENABLED=0 $(GO) build -ldflags="$(LDFLAGS)" $(GOFLAGS) -o mycorrhiza . + CGO_ENABLED=0 $(GO) build $(GOFLAGS) -o mycorrhiza . install: mkdir -m755 -p $(DESTDIR)$(BINDIR) $(DESTDIR)$(MANDIR)/man1 diff --git a/version/version.go b/version/version.go index 708a0d6..84dcd39 100644 --- a/version/version.go +++ b/version/version.go @@ -1,25 +1,35 @@ package version import ( + "regexp" "runtime/debug" "strconv" + + "github.com/bouncepaw/mycorrhiza/help" ) -// This is set through ldflags='-X ...' in the Makefile -var taggedRelease string = "unknown" +var tag = "unknown" +var versionRegexp = regexp.MustCompile(`This is documentation for \*\*Mycorrhiza Wiki\*\* (.*).`) + +func init() { + if b, err := help.Get("en"); err == nil { + matches := versionRegexp.FindSubmatch(b) + if matches != nil { + tag = "v" + string(matches[1]) + } + } +} func FormatVersion() string { - var commitHash string = "" - var dirty string = "" - + var commit, dirty string info, ok := debug.ReadBuildInfo() if ok { for _, setting := range info.Settings { if setting.Key == "vcs.revision" { - commitHash = "+" + setting.Value - if len(commitHash) > 8 { - commitHash = commitHash[:8] + commit = "+" + setting.Value + if len(commit) > 8 { + commit = commit[:8] } } else if setting.Key == "vcs.modified" { modified, err := strconv.ParseBool(setting.Value) @@ -30,5 +40,5 @@ func FormatVersion() string { } } - return taggedRelease + commitHash + dirty + return tag + commit + dirty }