Skip to content

Commit 9bae8eb

Browse files
committed
Add build info
1 parent cae931f commit 9bae8eb

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

version.go

+23-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ package main
22

33
import (
44
"fmt"
5+
"strings"
6+
7+
"runtime/debug"
58

69
"github.com/spf13/cobra"
710
)
@@ -19,5 +22,24 @@ func init() {
1922
}
2023

2124
func versionInfo(cmd *cobra.Command, args []string) {
22-
fmt.Printf("ntt %v, commit %v, built at %v\n", version, commit, date)
25+
if version == "dev" {
26+
info, ok := debug.ReadBuildInfo()
27+
if ok && strings.HasPrefix(info.Main.Version, "v") {
28+
version = info.Main.Version
29+
}
30+
for _, s := range info.Settings {
31+
switch s.Key {
32+
case "vcs.time":
33+
date = s.Value
34+
case "vcs.revision":
35+
commit = s.Value
36+
case "vcs.modified":
37+
if s.Value == "true" {
38+
commit += "-dirty"
39+
}
40+
}
41+
}
42+
}
43+
44+
fmt.Printf("ntt %v, commit %s, built at %s\n", version, commit, date)
2345
}

0 commit comments

Comments
 (0)