1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2024-12-04 18:19:54 +00:00

Change version package API

This commit is contained in:
Umar Getagazov 2022-09-14 10:38:36 +03:00
parent 8850b50624
commit ab848247c9
4 changed files with 17 additions and 15 deletions

View File

@ -42,7 +42,7 @@ func parseCliArgs() {
flag.Parse()
if versionFlag {
fmt.Println("Mycorrhiza Wiki", version.FormatVersion())
fmt.Println("Mycorrhiza Wiki", version.Long)
os.Exit(0)
}

View File

@ -37,7 +37,7 @@ func main() {
log.Fatal(err)
}
log.Println("Running Mycorrhiza Wiki", version.FormatVersion())
log.Println("Running Mycorrhiza Wiki", version.Short)
if err := os.Chdir(files.HyphaeDir()); err != nil {
log.Fatal(err)
}

View File

@ -98,7 +98,7 @@ func AboutHTML(lc *l18n.Localizer) string {
log.Fatalln(err)
}
data := aboutData
data.Version = version.FormatVersion()
data.Version = version.Short
data.Admins = user.ListUsersWithGroup("admin")
data.UserCount = user.Count()
data.RegistrationLimit = cfg.RegistrationLimit

View File

@ -8,37 +8,39 @@ import (
"github.com/bouncepaw/mycorrhiza/help"
)
var tag = "unknown"
// 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
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])
Short = string(matches[1])
}
}
}
func FormatVersion() string {
var commit, dirty string
Long = Short
info, ok := debug.ReadBuildInfo()
if ok {
for _, setting := range info.Settings {
if setting.Key == "vcs.revision" {
commit = "+" + setting.Value
if len(commit) > 8 {
commit = commit[:8]
val := setting.Value
if len(val) > 7 {
val = val[:7]
}
Long += "+" + val
} else if setting.Key == "vcs.modified" {
modified, err := strconv.ParseBool(setting.Value)
if err == nil && modified {
dirty = "-dirty"
Long += "-dirty"
}
}
}
}
return tag + commit + dirty
}