From d4194bb18c64a6fc7d3d5d0ae679c49f5a62877a Mon Sep 17 00:00:00 2001 From: lyyyuna Date: Sat, 4 Jul 2020 15:10:25 +0800 Subject: [PATCH] auto version --- cmd/version.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/cmd/version.go b/cmd/version.go index 833f772..5345341 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -18,6 +18,7 @@ package cmd import ( "fmt" + "runtime/debug" "github.com/spf13/cobra" ) @@ -33,7 +34,15 @@ var versionCmd = &cobra.Command{ goc version `, Run: func(cmd *cobra.Command, args []string) { - fmt.Println(version) + // if it is "Unstable", means user build local or with go get + if version == "Unstable" { + if info, ok := debug.ReadBuildInfo(); ok { + fmt.Println(info.Main.Version) + } + } else { + // otherwise the value is injected in CI + fmt.Println(version) + } }, }