diff --git a/Makefile b/Makefile index 933cb36..0d74847 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,7 @@ +VERSION=$(shell git describe --tags) + build: - go build + go build -ldflags="-X main.Version=$(VERSION)" test: go test diff --git a/version.go b/version.go index 7d11cb3..229c60c 100644 --- a/version.go +++ b/version.go @@ -3,14 +3,24 @@ package main import ( "flag" "fmt" + "runtime/debug" ) -const AppVersion = "v0.2.0" +var Version string type versionCmd struct{} func (cmd *versionCmd) run(args []string) error { - fmt.Println("hkt version ", AppVersion) + // TODO: Use Settings.VCS.Version from Go v1.18 + if Version == "" { + info, ok := debug.ReadBuildInfo() + if ok { + Version = info.Main.Version + } else { + Version = "devel" + } + } + fmt.Println("hkt version", Version) return nil }