Skip to content

Commit

Permalink
[main] read version info from the binary when not set
Browse files Browse the repository at this point in the history
  • Loading branch information
draxil committed Aug 2, 2022
1 parent 5290616 commit cb8b5e7
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions json2nd.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import (
"flag"
"fmt"
"os"
"runtime/debug"
)

var version = "dev"
var version = ""

func main() {

Expand Down Expand Up @@ -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)
}

Expand Down

0 comments on commit cb8b5e7

Please sign in to comment.