1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2024-10-30 03:36:16 +00:00
mycorrhiza/version/version.go

47 lines
971 B
Go
Raw Permalink Normal View History

2022-08-17 08:13:57 +00:00
package version
import (
"regexp"
2022-08-17 08:13:57 +00:00
"runtime/debug"
"strconv"
"github.com/bouncepaw/mycorrhiza/help"
2022-08-17 08:13:57 +00:00
)
2022-09-14 07:38:36 +00:00
// Long is the full version string, including VCS information, that looks like
// x.y.z+hash-dirty.
var Long string
// Short is the human-friendly x.y.z part of the long version string.
var Short string
2023-04-07 12:45:09 +00:00
var versionRegexp = regexp.MustCompile(`This is documentation for Mycorrhiza Wiki (.*)\. `)
2022-08-17 08:13:57 +00:00
func init() {
if b, err := help.Get("en"); err == nil {
matches := versionRegexp.FindSubmatch(b)
if matches != nil {
2022-09-14 07:38:36 +00:00
Short = string(matches[1])
}
}
2022-08-17 08:13:57 +00:00
2022-09-14 07:38:36 +00:00
Long = Short
2022-08-17 08:13:57 +00:00
info, ok := debug.ReadBuildInfo()
if ok {
for _, setting := range info.Settings {
if setting.Key == "vcs.revision" {
2022-09-14 07:38:36 +00:00
val := setting.Value
if len(val) > 7 {
val = val[:7]
}
2022-09-14 07:38:36 +00:00
Long += "+" + val
2022-08-17 08:13:57 +00:00
} else if setting.Key == "vcs.modified" {
modified, err := strconv.ParseBool(setting.Value)
if err == nil && modified {
2022-09-14 07:38:36 +00:00
Long += "-dirty"
2022-08-17 08:13:57 +00:00
}
}
}
}
}