Compare commits

...

10 Commits

4 changed files with 54 additions and 15 deletions

View File

@ -1,15 +1,15 @@
BUILD_VERSION := $(shell cat version)
BUILD_TIME := $(shell date "+%F %T")
COMMIT_SHA1 := $(shell git rev-parse HEAD)
ROOT_DIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))/
ROOT_DIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
DIST_DIR := $(ROOT_DIR)/dist/
VERSION_PATH := $(shell cat `go env GOMOD` | awk '/^module/{print $$2}')/metadata
LD_GIT_COMMIT := -X '$(VERSION_PATH).GitCommit=$(COMMIT_SHA1)'
LD_BUILD_TIME := -X '$(VERSION_PATH).BuildTime=$(BUILD_TIME)'
LD_GO_VERSION := -X '$(VERSION_PATH).GoVersion=`go version`'
LD_GATEWAY_VERSION := -X '$(VERSION_PATH).Version=$(BUILD_VERSION)'
LD_FLAGS := "$(LD_GIT_COMMIT) $(LD_BUILD_TIME) $(LD_GO_VERSION) $(LD_GATEWAY_VERSION) -w -s"
VERSION_PATH := $(shell cat `go env GOMOD` | awk '/^module/{print $$2}')/metadata
LD_GIT_COMMIT := -X '$(VERSION_PATH).GitCommit=$(COMMIT_SHA1)'
LD_BUILD_TIME := -X '$(VERSION_PATH).BuildTime=$(BUILD_TIME)'
LD_GO_VERSION := -X '$(VERSION_PATH).GoVersion=`go version`'
LD_VERSION := -X '$(VERSION_PATH).Version=$(BUILD_VERSION)'
LD_FLAGS := "$(LD_GIT_COMMIT) $(LD_BUILD_TIME) $(LD_GO_VERSION) $(LD_VERSION) -w -s"
.PHONY : build release clean install upx
@ -18,7 +18,7 @@ ifneq ($(shell type gox >/dev/null 2>&1;echo $$?), 0)
@echo "Can't find gox command, will start installation..."
GO111MODULE=off go get -v -u github.com/mitchellh/gox
endif
# @$(if $(findstring 0,$(shell type gox >/dev/null 2>&1;echo $$?)),,echo "Can't find gox command, will start installation...";GO111MODULE=off go get -v -u github.com/mitchellh/gox)
@# $(if $(findstring 0,$(shell type gox >/dev/null 2>&1;echo $$?)),,echo "Can't find gox command, will start installation...";GO111MODULE=off go get -v -u github.com/mitchellh/gox)
gox -ldflags $(LD_FLAGS) -osarch="darwin/amd64 linux/386 linux/amd64 windows/amd64" \
-output="$(DIST_DIR){{.Dir}}_{{.OS}}_{{.Arch}}"
@ -26,10 +26,17 @@ clean:
rm -rf $(DIST_DIR)*
install:
go install -ldflags $(LD_FLAGS)
@# go install -ldflags $(LD_FLAGS)
go build -ldflags $(LD_FLAGS) -o $(GOBIN)/hc
# 如果一个规则是以 .IGNORE 作为目标的,那么这个规则中所有命令都将会忽略错误
.IGNORE:
upx
# 压缩。需要安装 https://github.com/upx/upx
upx:
@# 在命令前面加上 "-",表示不管该命令出不出错,后面的命令都将继续执行下去
@# -upx $(DIST_DIR)**
upx $(DIST_DIR)**
release: build upx
@ -37,7 +44,7 @@ ifneq ($(shell type ghr >/dev/null 2>&1;echo $$?), 0)
@echo "Can't find ghr command, will start installation..."
GO111MODULE=off go get -v -u github.com/tcnksm/ghr
endif
# @$(if $(findstring 0,$(shell type ghr >/dev/null 2>&1;echo $$?)),,echo "Can't find ghr command, will start installation...";GO111MODULE=off go get -v -u github.com/tcnksm/ghr)
@# $(if $(findstring 0,$(shell type ghr >/dev/null 2>&1;echo $$?)),,echo "Can't find ghr command, will start installation...";GO111MODULE=off go get -v -u github.com/tcnksm/ghr)
ghr -u ehlxr -t $(GITHUB_RELEASE_TOKEN) -replace -delete --debug ${BUILD_VERSION} $(DIST_DIR)
# this tells 'make' to export all variables to child processes by default.

View File

@ -1,6 +1,12 @@
# hex-convert
```
[![license](https://badgen.net/badge/license/MIT/blue)](./LICENSE)
[![](https://badgen.net/github/commits/ehlxr/hex-convert)](https://github.com/ehlxr/hex-convert/commits/)
[![](https://badgen.net/github/last-commit/ehlxr/hex-convert)]((https://github.com/ehlxr/hex-convert/commits/))
[![](https://badgen.net/github/releases/ehlxr/hex-convert)](https://github.com/ehlxr/hex-convert/releases)
```shell
支持 76 位以内的任意进制相互转换
Usage:
@ -13,10 +19,30 @@ Available Commands:
help Help about any command
o 转换为八进制
server 启动 HTTP Server
version Print version
Flags:
-d, --data string 要转换数值
-h, --help help for hc
-s, --scale int 要转换的进制
-v, --version show version of the hc.
Use "hc [command] --help" for more information about a command.
```
```shell
➜ hex-convert version
__ __
/ /_ ___ _ __ _________ ____ _ _____ _____/ /_
/ __ \/ _ \| |/_/_____/ ___/ __ \/ __ \ | / / _ \/ ___/ __/
/ / / / __/> </_____/ /__/ /_/ / / / / |/ / __/ / / /_
/_/ /_/\___/_/|_| \___/\____/_/ /_/|___/\___/_/ \__/
Name: hc
Version: v1.0.1
BuildTime: 2019-10-02 17:26:13
GitCommit: ede4bd17e9749a011d4bcec953db0ae6b6c5695b
GoVersion: go version go1.13.1 darwin/amd64
```

View File

@ -40,6 +40,8 @@ var serverCmd = &cobra.Command{
host := cmd.LocalFlags().Lookup("host").Value.String()
port, _ := strconv.Atoi(cmd.LocalFlags().Lookup("port").Value.String())
printVersion()
if err := server.Start(host, port); err != nil {
fmt.Println(err)
os.Exit(1)

View File

@ -30,12 +30,12 @@ import (
)
var versionTpl = `%s
Name: hc
Version: %s
BuildTime: %s
GitCommit: %s
GoVersion: %s
`
// versionCmd represents the version command
@ -45,11 +45,15 @@ var versionCmd = &cobra.Command{
Long: `
Print version of jwt`,
Run: func(cmd *cobra.Command, args []string) {
banner, _ := base64.StdEncoding.DecodeString(metadata.BannerBase64)
fmt.Printf(versionTpl, banner, metadata.Version, metadata.BuildTime, metadata.GitCommit, metadata.GoVersion)
printVersion()
},
}
func printVersion() {
banner, _ := base64.StdEncoding.DecodeString(metadata.BannerBase64)
fmt.Printf(versionTpl, banner, metadata.Version, metadata.BuildTime, metadata.GitCommit, metadata.GoVersion)
}
func init() {
rootCmd.AddCommand(versionCmd)
}