Skip to content

Commit 1887d62

Browse files
committed
Compile version information into GRV
1 parent 21045f4 commit 1887d62

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

Makefile

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
1+
VERSION=$(shell git describe --long --tags --dirty --always 2>/dev/null || echo 'Unknown')
2+
HEAD_OID=$(shell git rev-parse --short HEAD 2>/dev/null || echo 'Unknown')
3+
BUILD_DATETIME=$(shell date '+%Y-%m-%d %H:%M:%S %Z')
4+
15
GOCMD=go
26
GOLINT=golint
37

48
BINARY?=grv
59
SOURCE_DIR=./cmd/grv
6-
BUILD_FLAGS=--tags static
7-
STATIC_BUILD_FLAGS=$(BUILD_FLAGS) -ldflags "-extldflags '-lncurses -ltinfo -lgpm -static'"
10+
LDFLAGS=-X 'main.version=$(VERSION)' -X 'main.headOid=$(HEAD_OID)' -X 'main.buildDateTime=$(BUILD_DATETIME)'
11+
STATIC_LDFLAGS=-extldflags '-lncurses -ltinfo -lgpm -static'
12+
BUILD_FLAGS=--tags static -ldflags "$(LDFLAGS)"
13+
STATIC_BUILD_FLAGS=--tags static -ldflags "$(LDFLAGS) $(STATIC_LDFLAGS)"
814

915
GRV_DIR:=$(dir $(realpath $(lastword $(MAKEFILE_LIST))))
1016
GOPATH_DIR:=$(GRV_DIR)../../../..

cmd/grv/main.go

+18
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,26 @@ const (
1515
MnLogLevelDefault = "NONE"
1616
)
1717

18+
var (
19+
version = "Unknown"
20+
headOid = "Unknown"
21+
buildDateTime = "Unknown"
22+
)
23+
1824
type grvArgs struct {
1925
repoFilePath string
2026
logLevel string
2127
logFilePath string
28+
version bool
2229
}
2330

2431
func main() {
2532
args := parseArgs()
33+
if args.version {
34+
printVersion()
35+
return
36+
}
37+
2638
InitialiseLogging(args.logLevel, args.logFilePath)
2739

2840
log.Debugf("Creating GRV instance")
@@ -45,12 +57,18 @@ func parseArgs() *grvArgs {
4557
repoFilePathPtr := flag.String("repoFilePath", mnRepoFilePathDefault, "Repository file path")
4658
logLevelPtr := flag.String("logLevel", MnLogLevelDefault, "Logging level [NONE|PANIC|FATAL|ERROR|WARN|INFO|DEBUG]")
4759
logFilePathPtr := flag.String("logFile", mnLogFilePathDefault, "Log file path")
60+
versionPtr := flag.Bool("version", false, "Print version")
4861

4962
flag.Parse()
5063

5164
return &grvArgs{
5265
repoFilePath: *repoFilePathPtr,
5366
logLevel: *logLevelPtr,
5467
logFilePath: *logFilePathPtr,
68+
version: *versionPtr,
5569
}
5670
}
71+
72+
func printVersion() {
73+
fmt.Printf("GRV - Git Repository Viewer %v (commit: %v, compiled: %v)\n", version, headOid, buildDateTime)
74+
}

0 commit comments

Comments
 (0)