diff --git a/Makefile b/Makefile index ebeb27c..e4d0faa 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,8 @@ .DEFAULT_GOAL:=local_or_with_proxy USE_PROXY=GOPROXY=https://goproxy.io -BUILD=go build -ldflags "-s -w" +VERSION:=$(shell git describe --abbrev=7 --dirty --always --tags) +BUILD=go build -ldflags "-s -w -X main.Version=$(VERSION)" BUILD_DIR=build BIN_DIR=$(GOOS)-$(GOARCH) BIN_NAME=nkn-tunnel diff --git a/bin/main.go b/bin/main.go index f34d93e..a229f79 100644 --- a/bin/main.go +++ b/bin/main.go @@ -3,6 +3,7 @@ package main import ( "encoding/hex" "flag" + "fmt" "log" "strings" @@ -12,6 +13,10 @@ import ( "github.com/nknorg/tuna" ) +var ( + Version string +) + func main() { numClients := flag.Int("n", 4, "number of clients") seedHex := flag.String("s", "", "secret seed") @@ -23,9 +28,15 @@ func main() { tunaMaxPrice := flag.String("tuna-max-price", "0.01", "tuna max price in unit of NKN/MB") mtu := flag.Int("mtu", 0, "ncp session mtu") verbose := flag.Bool("v", false, "show logs on dialing/accepting connection") + version := flag.Bool("version", false, "print version") flag.Parse() + if *version { + fmt.Println(Version) + return + } + if len(*from) == 0 { log.Fatal("From address is empty") }