diff --git a/version.go b/version.go index efa99efb..201cbb87 100644 --- a/version.go +++ b/version.go @@ -2,6 +2,9 @@ package main import ( "fmt" + "strings" + + "runtime/debug" "github.com/spf13/cobra" ) @@ -19,5 +22,24 @@ func init() { } func versionInfo(cmd *cobra.Command, args []string) { - fmt.Printf("ntt %v, commit %v, built at %v\n", version, commit, date) + if version == "dev" { + info, ok := debug.ReadBuildInfo() + if ok && strings.HasPrefix(info.Main.Version, "v") { + version = info.Main.Version + } + for _, s := range info.Settings { + switch s.Key { + case "vcs.time": + date = s.Value + case "vcs.revision": + commit = s.Value + case "vcs.modified": + if s.Value == "true" { + commit += "-dirty" + } + } + } + } + + fmt.Printf("ntt %v, commit %s, built at %s\n", version, commit, date) }