mirror of
https://github.com/osmarks/mycorrhiza.git
synced 2024-12-12 13:30:26 +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
|
BINDIR=$(PREFIX)/bin
|
||||||
MANDIR=$(PREFIX)/share/man
|
MANDIR=$(PREFIX)/share/man
|
||||||
GO=go
|
GO=go
|
||||||
LDFLAGS=-X "github.com/bouncepaw/mycorrhiza/version.taggedRelease=$$(git describe --tags --abbrev=0)"
|
|
||||||
|
|
||||||
all: mycorrhiza
|
all: mycorrhiza
|
||||||
|
|
||||||
mycorrhiza:
|
mycorrhiza:
|
||||||
$(GO) generate $(GOFLAGS)
|
$(GO) generate $(GOFLAGS)
|
||||||
CGO_ENABLED=0 $(GO) build -ldflags="$(LDFLAGS)" $(GOFLAGS) -o mycorrhiza .
|
CGO_ENABLED=0 $(GO) build $(GOFLAGS) -o mycorrhiza .
|
||||||
|
|
||||||
install:
|
install:
|
||||||
mkdir -m755 -p $(DESTDIR)$(BINDIR) $(DESTDIR)$(MANDIR)/man1
|
mkdir -m755 -p $(DESTDIR)$(BINDIR) $(DESTDIR)$(MANDIR)/man1
|
||||||
|
@ -1,25 +1,35 @@
|
|||||||
package version
|
package version
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"regexp"
|
||||||
"runtime/debug"
|
"runtime/debug"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
|
"github.com/bouncepaw/mycorrhiza/help"
|
||||||
)
|
)
|
||||||
|
|
||||||
// This is set through ldflags='-X ...' in the Makefile
|
var tag = "unknown"
|
||||||
var taggedRelease string = "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 {
|
func FormatVersion() string {
|
||||||
var commitHash string = ""
|
var commit, dirty string
|
||||||
var dirty string = ""
|
|
||||||
|
|
||||||
info, ok := debug.ReadBuildInfo()
|
info, ok := debug.ReadBuildInfo()
|
||||||
|
|
||||||
if ok {
|
if ok {
|
||||||
for _, setting := range info.Settings {
|
for _, setting := range info.Settings {
|
||||||
if setting.Key == "vcs.revision" {
|
if setting.Key == "vcs.revision" {
|
||||||
commitHash = "+" + setting.Value
|
commit = "+" + setting.Value
|
||||||
if len(commitHash) > 8 {
|
if len(commit) > 8 {
|
||||||
commitHash = commitHash[:8]
|
commit = commit[:8]
|
||||||
}
|
}
|
||||||
} else if setting.Key == "vcs.modified" {
|
} else if setting.Key == "vcs.modified" {
|
||||||
modified, err := strconv.ParseBool(setting.Value)
|
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