package briefversion import ( "log" "runtime/debug" "time" "pkg.jfrech.com/brief/internal/crumbs" ) // Does NOT add a "brief " or "Brief " prefix. // // Used in "brief version". func Version() string { if version == "" || version[0] != 'v' { return "vQ" } return version } // Used in internal/manpages. func VersionDate() time.Time { if versionDate.IsZero() { return time.Time{} } return versionDate } var ( version string versionDate time.Time ) func init() { // Cf. https://pkg.go.dev/runtime/debug@go1.21.5#BuildSetting [accessed 2023-12-11] const ( vcsRevision = "vcs.revision" vcsModified = "vcs.modified" vcsTime = "vcs.time" vcsTimeLayout = time.RFC3339 ) take := crumbs.StringTake info, ok := debug.ReadBuildInfo() if !ok { log.Printf("warning: Brief built without build info") // [2024-01-01, jfrech] TODO consider return } h := make(map[string]string) for _, kv := range info.Settings { h[kv.Key] += kv.Value } version = info.Main.Version if version == "(devel)" { version = "v" + take(8, h[vcsRevision]) if h[vcsModified] != "false" { version += "*" } } if t, err := time.Parse(vcsTimeLayout, h[vcsTime]); err == nil && !t.IsZero() { if loc, err := time.LoadLocation("Europe/Berlin"); err == nil { t = t.In(loc) } else if true { t = t.In(time.FixedZone("CET", +01*60*60)) } versionDate = t } } func XMailer() string { return "Brief " + Version() + " (https://brief.software.jfrech.com/)" }