Skip to content

Commit

Permalink
Feature: add version command (#148)
Browse files Browse the repository at this point in the history
  • Loading branch information
beyondkmp authored and Dreamacro committed Mar 23, 2019
1 parent f99da37 commit bb267e4
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
10 changes: 7 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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 \
Expand Down Expand Up @@ -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)

Expand Down
6 changes: 6 additions & 0 deletions constant/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package constant

var (
Version = "unknown version"
BuildTime = "unknown time"
)
9 changes: 9 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package main

import (
"flag"
"fmt"
"os"
"os/signal"
"path/filepath"
"runtime"
"syscall"

"github.com/Dreamacro/clash/config"
Expand All @@ -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")

Expand Down

0 comments on commit bb267e4

Please sign in to comment.