|
|
@@ -9,7 +9,10 @@
|
|
9
|
9
|
package main
|
|
10
|
10
|
|
|
11
|
11
|
import (
|
|
|
12
|
+ "fmt"
|
|
12
|
13
|
"math/rand"
|
|
|
14
|
+ "runtime/debug"
|
|
|
15
|
+ "strconv"
|
|
13
|
16
|
"time"
|
|
14
|
17
|
|
|
15
|
18
|
"github.com/9seconds/mtg/v2/internal/cli"
|
|
|
@@ -26,6 +29,32 @@ func main() {
|
|
26
|
29
|
panic(err)
|
|
27
|
30
|
}
|
|
28
|
31
|
|
|
|
32
|
+ if buildInfo, ok := debug.ReadBuildInfo(); ok {
|
|
|
33
|
+ vcsCommit := "<no-commit>"
|
|
|
34
|
+ vcsDate := time.Now()
|
|
|
35
|
+ vcsDirty := ""
|
|
|
36
|
+
|
|
|
37
|
+ for _, setting := range buildInfo.Settings {
|
|
|
38
|
+ switch setting.Key {
|
|
|
39
|
+ case "vcs.time":
|
|
|
40
|
+ vcsDate, _ = time.Parse(time.RFC3339, setting.Value)
|
|
|
41
|
+ case "vcs.revision":
|
|
|
42
|
+ vcsCommit = setting.Value
|
|
|
43
|
+ case "vcs.modified":
|
|
|
44
|
+ if isDirty, _ := strconv.ParseBool(setting.Value); isDirty {
|
|
|
45
|
+ vcsDirty = " [dirty]"
|
|
|
46
|
+ }
|
|
|
47
|
+ }
|
|
|
48
|
+ }
|
|
|
49
|
+
|
|
|
50
|
+ version = fmt.Sprintf("%s (%s: %s on %s%s)",
|
|
|
51
|
+ version,
|
|
|
52
|
+ buildInfo.GoVersion,
|
|
|
53
|
+ vcsDate.Format(time.RFC3339),
|
|
|
54
|
+ vcsCommit,
|
|
|
55
|
+ vcsDirty)
|
|
|
56
|
+ }
|
|
|
57
|
+
|
|
29
|
58
|
cli := &cli.CLI{}
|
|
30
|
59
|
ctx := kong.Parse(cli, kong.Vars{
|
|
31
|
60
|
"version": version,
|