mirror of
https://github.com/osmarks/mycorrhiza.git
synced 2024-10-30 03:36:16 +00:00
Get version from the help
I'm going to get executed for this crime
This commit is contained in:
parent
ebe618ed1f
commit
8850b50624
3
Makefile
3
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
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user