Use embedded buildinfo

This commit is contained in:
9seconds
2022-03-18 18:06:56 +03:00
parent 02ad052c49
commit 5df1f594cc
2 changed files with 31 additions and 4 deletions
+29
View File
@@ -9,7 +9,10 @@
package main
import (
"fmt"
"math/rand"
"runtime/debug"
"strconv"
"time"
"github.com/9seconds/mtg/v2/internal/cli"
@@ -26,6 +29,32 @@ func main() {
panic(err)
}
if buildInfo, ok := debug.ReadBuildInfo(); ok {
vcsCommit := "<no-commit>"
vcsDate := time.Now()
vcsDirty := ""
for _, setting := range buildInfo.Settings {
switch setting.Key {
case "vcs.time":
vcsDate, _ = time.Parse(time.RFC3339, setting.Value)
case "vcs.revision":
vcsCommit = setting.Value
case "vcs.modified":
if isDirty, _ := strconv.ParseBool(setting.Value); isDirty {
vcsDirty = " [dirty]"
}
}
}
version = fmt.Sprintf("%s (%s: %s on %s%s)",
version,
buildInfo.GoVersion,
vcsDate.Format(time.RFC3339),
vcsCommit,
vcsDirty)
}
cli := &cli.CLI{}
ctx := kong.Parse(cli, kong.Vars{
"version": version,