diff --git a/cmd/version.go b/cmd/version.go index 0e51fee..f04fdfb 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -2,6 +2,7 @@ package cmd import ( "fmt" + "runtime/debug" "github.com/spf13/cobra" ) @@ -13,6 +14,12 @@ var versionCmd = &cobra.Command{ Use: "version", Short: "Print the go-readme version", Run: func(cmd *cobra.Command, _ []string) { - fmt.Fprintf(cmd.OutOrStdout(), "go-readme %s\n", Version) + version := Version + if version == "dev" { + if info, ok := debug.ReadBuildInfo(); ok && info.Main.Version != "" && info.Main.Version != "(devel)" { + version = info.Main.Version + } + } + fmt.Fprintf(cmd.OutOrStdout(), "go-readme %s\n", version) }, }