Skip to content

Commit 7d2d49c

Browse files
authored
Merge pull request #60 from lyyyuna/goc-auto-version
support goc version using `go get`
2 parents 6398d4f + d4194bb commit 7d2d49c

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

cmd/version.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package cmd
1818

1919
import (
2020
"fmt"
21+
"runtime/debug"
2122

2223
"github.com/spf13/cobra"
2324
)
@@ -33,7 +34,15 @@ var versionCmd = &cobra.Command{
3334
goc version
3435
`,
3536
Run: func(cmd *cobra.Command, args []string) {
36-
fmt.Println(version)
37+
// if it is "Unstable", means user build local or with go get
38+
if version == "Unstable" {
39+
if info, ok := debug.ReadBuildInfo(); ok {
40+
fmt.Println(info.Main.Version)
41+
}
42+
} else {
43+
// otherwise the value is injected in CI
44+
fmt.Println(version)
45+
}
3746
},
3847
}
3948

0 commit comments

Comments
 (0)