Skip to content

Commit

Permalink
✨feat:add show version
Browse files Browse the repository at this point in the history
  • Loading branch information
HanHan666666 committed Jul 16, 2023
1 parent c4cb8bf commit 974ae1b
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# Output of the go coverage tool, specifically when used with LiteIDE
*.out
.idea/
#output/
output/
CodeMerged.txt
# Dependency directories (remove the comment below to include it)
# vendor/
Expand Down
54 changes: 54 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
VERSION=$(shell git describe --tags `git rev-list --tags --max-count=1`)
BUILD_TIME=$(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
GITCOMMIT=$(shell git rev-parse HEAD)

GOVERSION=$(shell go version)

GO_FLAGS=-ldflags="-X 'main.VERSION=$(VERSION)' -X 'main.BUILDTIME=$(BUILD_TIME)' -X 'main.GITCOMMIT=$(GITCOMMIT)' -X 'main.GOVERSION=$(GOVERSION)' -extldflags -static -s -w" -trimpath


BINARY=CodeMerge
DIR=output

build:
go build ${GO_FLAGS}

install:
go install ${GO_FLAGS}

debug:
go clean
# build for linux_amd64
GOOS=linux GOARCH=amd64 go build -o ${DIR}/${BINARY}_linux_amd64
# build for linux_arm64
GOOS=linux GOARCH=arm64 go build -o ${DIR}/${BINARY}_linux_arm64
# build for windows_amd64
GOOS=windows GOARCH=amd64 go build -o ${DIR}/${BINARY}_windows_amd64.exe
# build for windows_arm64
GOOS=windows GOARCH=arm64 go build -o ${DIR}/${BINARY}_windows_arm64.exe
# build for darwin_amd64
GOOS=darwin GOARCH=amd64 go build -o ${DIR}/${BINARY}_darwin_amd64
# build for darwin_arm64
GOOS=darwin GOARCH=arm64 go build -o ${DIR}/${BINARY}_darwin_arm64

release:
go clean
CGO_ENABLED=0

# build for linux_amd64
GOOS=linux GOARCH=amd64 go build ${GO_FLAGS} -o ${DIR}/${BINARY}_linux_amd64
# build for linux_arm64
GOOS=linux GOARCH=arm64 go build ${GO_FLAGS} -o ${DIR}/${BINARY}_linux_arm64
# build for windows_amd64
GOOS=windows GOARCH=amd64 go build ${GO_FLAGS} -o ${DIR}/${BINARY}_windows_amd64.exe
# build for windows_arm64
GOOS=windows GOARCH=arm64 go build ${GO_FLAGS} -o ${DIR}/${BINARY}_windows_arm64.exe
# build for darwin_amd64
GOOS=darwin GOARCH=amd64 go build ${GO_FLAGS} -o ${DIR}/${BINARY}_darwin_amd64
# build for darwin_arm64
GOOS=darwin GOARCH=arm64 go build ${GO_FLAGS} -o ${DIR}/${BINARY}_darwin_arm64

clean:
go clean

.PHONY: clean build
24 changes: 0 additions & 24 deletions internal/version.go
Original file line number Diff line number Diff line change
@@ -1,25 +1 @@
package internal

import (
"fmt"
"os"
)

var VERSION = "DEV-1.0"
var GOVERSION = "UNKNOWN"
var GITCOMMIT = "UNKNOWN*"
var BUILDTIME = "UNKNOWN"

func version() string {
return fmt.Sprintf(`CodeMerge %s
Git commit: %s,
Build with %s
Build at %s`, VERSION, GITCOMMIT, GOVERSION, BUILDTIME)
}

func ShowVersion(showVersion *bool) {
if *showVersion {
fmt.Println(version())
os.Exit(0)
}
}
21 changes: 20 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ import (
"path/filepath"
)

var VERSION = "DEV-1.0"
var GOVERSION = "UNKNOWN"
var GITCOMMIT = "UNKNOWN*"
var BUILDTIME = "UNKNOWN"

func main() {
dir, _ := os.Getwd()

Expand All @@ -22,7 +27,7 @@ func main() {

flag.Parse()

internal.ShowVersion(showVersion)
ShowVersion(showVersion)

//输出当前所在目录
fmt.Println("当前目录:", dir)
Expand Down Expand Up @@ -66,3 +71,17 @@ func main() {

fmt.Println("合并成功!")
}

func version() string {
return fmt.Sprintf(`CodeMerge %s
Git commit: %s,
Build with %s
Build at %s`, VERSION, GITCOMMIT, GOVERSION, BUILDTIME)
}

func ShowVersion(showVersion *bool) {
if *showVersion {
fmt.Println(version())
os.Exit(0)
}
}

0 comments on commit 974ae1b

Please sign in to comment.