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() flag.Parse()
if versionFlag { if versionFlag {
fmt.Println("Mycorrhiza Wiki", version.FormatVersion()) fmt.Println("Mycorrhiza Wiki", version.Long)
os.Exit(0) os.Exit(0)
} }

View File

@ -37,7 +37,7 @@ func main() {
log.Fatal(err) 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 { if err := os.Chdir(files.HyphaeDir()); err != nil {
log.Fatal(err) log.Fatal(err)
} }

View File

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

View File

@ -8,37 +8,39 @@ import (
"github.com/bouncepaw/mycorrhiza/help" "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\*\* (.*).`) var versionRegexp = regexp.MustCompile(`This is documentation for \*\*Mycorrhiza Wiki\*\* (.*).`)
func init() { func init() {
if b, err := help.Get("en"); err == nil { if b, err := help.Get("en"); err == nil {
matches := versionRegexp.FindSubmatch(b) matches := versionRegexp.FindSubmatch(b)
if matches != nil { if matches != nil {
tag = "v" + string(matches[1]) Short = string(matches[1])
} }
} }
}
func FormatVersion() string { Long = Short
var commit, 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" {
commit = "+" + setting.Value val := setting.Value
if len(commit) > 8 { if len(val) > 7 {
commit = commit[:8] val = val[:7]
} }
Long += "+" + val
} else if setting.Key == "vcs.modified" { } else if setting.Key == "vcs.modified" {
modified, err := strconv.ParseBool(setting.Value) modified, err := strconv.ParseBool(setting.Value)
if err == nil && modified { if err == nil && modified {
dirty = "-dirty" Long += "-dirty"
} }
} }
} }
} }
return tag + commit + dirty
} }