From e3c78f934efd6b624cc3b518ae3ed35019a6c1d4 Mon Sep 17 00:00:00 2001 From: gVisor bot Date: Sat, 23 Mar 2019 19:24:26 +0800 Subject: [PATCH] Feature: add version command (#148) --- Makefile | 10 +++++++--- constant/version.go | 6 ++++++ main.go | 9 +++++++++ 3 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 constant/version.go diff --git a/Makefile b/Makefile index a29a8e3e..8c5919ff 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,10 @@ NAME=clash BINDIR=bin -GOBUILD=CGO_ENABLED=0 go build -ldflags '-w -s' +VERSION=$(shell git describe --tags --long --dirty || echo "unkown version") +BUILDTIME=$(shell date -u) +GOBUILD=CGO_ENABLED=0 go build -ldflags '-X "github.com/Dreamacro/clash/constant.Version=$(VERSION)" \ + -X "github.com/Dreamacro/clash/constant.BuildTime=$(BUILDTIME)" \ + -w -s' PLATFORM_LIST = \ darwin-amd64 \ @@ -77,10 +81,10 @@ zip_releases=$(addsuffix .zip, $(WINDOWS_ARCH_LIST)) $(gz_releases): %.gz : % chmod +x $(BINDIR)/$(NAME)-$(basename $@) - gzip -f $(BINDIR)/$(NAME)-$(basename $@) + tar -czf $(BINDIR)/$(NAME)-$(basename $@)-$(VERSION).tar.gz -C $(BINDIR) $(NAME)-$(basename $@) $(zip_releases): %.zip : % - zip -m -j $(BINDIR)/$(NAME)-$(basename $@).zip $(BINDIR)/$(NAME)-$(basename $@).exe + zip -m -j $(BINDIR)/$(NAME)-$(basename $@)-$(VERSION).zip $(BINDIR)/$(NAME)-$(basename $@).exe all-arch: $(PLATFORM_LIST) $(WINDOWS_ARCH_LIST) diff --git a/constant/version.go b/constant/version.go new file mode 100644 index 00000000..17a26f8c --- /dev/null +++ b/constant/version.go @@ -0,0 +1,6 @@ +package constant + +var ( + Version = "unknown version" + BuildTime = "unknown time" +) diff --git a/main.go b/main.go index 77330101..2e9c4b25 100644 --- a/main.go +++ b/main.go @@ -2,9 +2,11 @@ package main import ( "flag" + "fmt" "os" "os/signal" "path/filepath" + "runtime" "syscall" "github.com/Dreamacro/clash/config" @@ -15,15 +17,22 @@ import ( ) var ( + version bool homedir string ) func init() { flag.StringVar(&homedir, "d", "", "set configuration directory") + flag.BoolVar(&version, "v", false, "show current version of clash") flag.Parse() } func main() { + if version { + fmt.Printf("Clash %s %s %s %s\n", C.Version, runtime.GOOS, runtime.GOARCH, C.BuildTime) + return + } + // enable tls 1.3 and remove when go 1.13 os.Setenv("GODEBUG", os.Getenv("GODEBUG")+",tls13=1")