From cb8b5e77bb0c0f9f41f760184f428e3cc14d1dae Mon Sep 17 00:00:00 2001 From: Joe Higton Date: Tue, 2 Aug 2022 08:50:01 +0100 Subject: [PATCH] [main] read version info from the binary when not set --- json2nd.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/json2nd.go b/json2nd.go index 1217e70..abd83fa 100644 --- a/json2nd.go +++ b/json2nd.go @@ -4,9 +4,10 @@ import ( "flag" "fmt" "os" + "runtime/debug" ) -var version = "dev" +var version = "" func main() { @@ -35,7 +36,17 @@ func flags() (tolerant bool, path string, args []string) { args = flag.Args() if *showVersion { - fmt.Println(version) + if version != "" { + fmt.Println(version) + } else { + info, ok := debug.ReadBuildInfo() + if ok { + fmt.Println(info.Main.Version) + } else { + fmt.Println("don't know") + } + } + os.Exit(0) }