File tree Expand file tree Collapse file tree 2 files changed +16
-7
lines changed
Expand file tree Collapse file tree 2 files changed +16
-7
lines changed Original file line number Diff line number Diff line change 1- APPNAME = commit-msg
1+ APPNAME : = commit-msg
22LDFLAGS += -s -w
33
44.PHONY : all build upx
55
66all : build upx
77
88build :
9- go build -trimpath -ldflags ' $(LDFLAGS)'
9+ go build -trimpath -ldflags " $( LDFLAGS) -X 'main.version= $( TAG ) ' -X 'main.goVersion= $( shell go version ) ' -X 'main.commitHash= $( shell git show -s --format=%H ) ' -X 'main.buildTime= $( shell date " +%Y-%m-%d %T%z " ) ' "
1010
1111upx :
1212 upx ` find -maxdepth 1 -name " $( APPNAME) " -o -name " $( APPNAME) .exe" `
Original file line number Diff line number Diff line change @@ -9,12 +9,12 @@ import (
99 "github.com/JayceChant/commit-msg/validator"
1010)
1111
12- const (
13- versionStr = "v0.2.0"
14- )
15-
1612var (
1713 versionFlag = flag .Bool ("version" , false , "" )
14+ version string
15+ goVersion string
16+ commitHash string
17+ buildTime string
1818)
1919
2020func main () {
@@ -33,5 +33,14 @@ func main() {
3333}
3434
3535func printVersion (cmd string ) {
36- fmt .Printf ("%s %s\n " , filepath .Base (cmd ), versionStr )
36+ fmt .Println (filepath .Base (cmd ), version )
37+ if goVersion != "" {
38+ fmt .Println (goVersion )
39+ }
40+ if commitHash != "" {
41+ fmt .Println ("commit hash :" , commitHash )
42+ }
43+ if buildTime != "" {
44+ fmt .Println ("build at :" , buildTime )
45+ }
3746}
You can’t perform that action at this time.
0 commit comments