Skip to content

Commit a8e2b7e

Browse files
committed
feat: cmd version based on module info.
1 parent 576a3a3 commit a8e2b7e

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

meta/version.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ package meta
33
import (
44
"fmt"
55
"runtime"
6+
"runtime/debug"
67
)
78

89
var (
910
version = "devel"
1011
commit = "-"
11-
date = "-"
12+
date = ""
1213
)
1314

1415
// GetVersion returns the current version.
@@ -18,6 +19,14 @@ func GetVersion() string {
1819

1920
// DisplayVersion Display version information.
2021
func DisplayVersion() {
22+
if info, available := debug.ReadBuildInfo(); available {
23+
if date == "" {
24+
version = info.Main.Version
25+
commit = fmt.Sprintf("(unknown, mod sum: %q)", info.Main.Sum)
26+
date = "(unknown)"
27+
}
28+
}
29+
2130
fmt.Printf(`prm:
2231
version : %s
2332
commit : %s

0 commit comments

Comments
 (0)