diff --git a/main.go b/main.go index e86fda50..d30f0a78 100644 --- a/main.go +++ b/main.go @@ -6,6 +6,7 @@ import ( "log" "os" "os/signal" + "runtime" "runtime/debug" "syscall" @@ -44,18 +45,34 @@ func parseFlag(args []string) { flag.CommandLine.Parse(args) } +func versionInfo() *debug.BuildInfo { + if info, ok := debug.ReadBuildInfo(); ok { + return info + } + return nil +} + func main() { - bi, ok := debug.ReadBuildInfo() - if ok { - fmt.Printf("bi: %v\n", bi) + versionInfo := versionInfo() + var goVersion string + var airVersion string + if versionInfo != nil { + goVersion = versionInfo.GoVersion + airVersion = versionInfo.Main.Version + } else { + airVersion = "(unknown version)" + goVersion = runtime.Version() } - goversion := bi.GoVersion + // TODO: how to get the version of the binary? gofumpt + // https://github.com/cosmtrek/air/issues/434 but just get devel :( + // https: // www.reddit.com/r/golang/comments/udhml7/best_way_to_embed_version_info_into_binary/ + // go embed maybe a good idea fmt.Printf(` __ _ ___ / /\ | | | |_) /_/--\ |_| |_| \_ %s, built with Go %s -`, airVersion, goversion) +`, airVersion, goVersion) if showVersion { return diff --git a/version.go b/version.go index a969d1b6..e8904dc4 100644 --- a/version.go +++ b/version.go @@ -1,4 +1,6 @@ package main -var airVersion string -var goVersion string +var ( + airVersion string + goVersion string +)