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:
parent
8850b50624
commit
ab848247c9
2
flag.go
2
flag.go
@ -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)
|
||||
}
|
||||
|
||||
|
2
main.go
2
main.go
@ -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)
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user