Skip to content

Commit 0bcd2db

Browse files
committed
show version when go install
1 parent 39c5352 commit 0bcd2db

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

main.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"os"
77
"path/filepath"
8+
"runtime/debug"
89
"strings"
910

1011
"github.com/umlx5h/zsh-manpage-completion-generator/internal/converter"
@@ -49,7 +50,14 @@ func main() {
4950
isVersion := *version_
5051

5152
if isVersion {
52-
fmt.Printf("Version: %s, Commit: %s, Date: %s\n", version, commit, date)
53+
if commit != "unset" {
54+
fmt.Printf("Version: %s, Commit: %s, Date: %s\n", version, commit, date)
55+
} else if buildInfo, ok := debug.ReadBuildInfo(); ok {
56+
fmt.Printf("Version: %s\n", buildInfo.Main.Version)
57+
} else {
58+
fmt.Printf("Version: %s\n", "(unknown)")
59+
}
60+
5361
os.Exit(0)
5462
}
5563

0 commit comments

Comments
 (0)