Skip to content

Commit 7d55630

Browse files
committed
set version when go install
1 parent bec4960 commit 7d55630

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

cmd/root.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@ package cmd
22

33
import (
44
"os"
5+
"runtime/debug"
56

67
"github.com/spf13/cobra"
78
)
89

910
var version string
1011

1112
var rootCmd = &cobra.Command{
12-
Use: "clive",
13-
Version: version,
14-
Short: "Automates terminal operations and lets you view them live via a browser",
15-
Long: "Automates terminal operations and lets you view them live via a browser.",
13+
Use: "clive",
14+
Short: "Automates terminal operations and lets you view them live via a browser",
15+
Long: "Automates terminal operations and lets you view them live via a browser.",
1616
}
1717

1818
func Execute() {
@@ -21,3 +21,13 @@ func Execute() {
2121
os.Exit(1)
2222
}
2323
}
24+
25+
func init() {
26+
if version == "" {
27+
if info, ok := debug.ReadBuildInfo(); ok {
28+
version = info.Main.Version
29+
}
30+
}
31+
32+
rootCmd.Version = version
33+
}

0 commit comments

Comments
 (0)