Skip to content

Commit

Permalink
Add Git commit short hash to -v
Browse files Browse the repository at this point in the history
  • Loading branch information
MichelBoucey committed Jul 27, 2024
1 parent 74f615e commit ca1b0bd
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

BUILD=go build -o dumber
MV=mv dumber ~/go/bin/dumber
VERSION=`grep -Po '\d*\.\d*\.\d*' main.go`
COMMIT_SHORT_SHA := $(shell git rev-parse --short HEAD)
BUILD=go build -o dumber -ldflags "-X 'main.commitShortHash=$(COMMIT_SHORT_SHA)'"
MV=sudo mv dumber ~/go/bin/dumber

help:
@echo "Usage:"
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module github.com/MichelBoucey/dumber

go 1.22.0
go 1.22.4
6 changes: 5 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ import (
"strings"
)

var (
commitShortHash = ""
)

func main() {

version := "2.1.0"
Expand Down Expand Up @@ -69,7 +73,7 @@ func main() {
flag.Parse()

if *versionFlag == true {
fmt.Println("dumber v" + version + newLine + "Copyright © 2021-2023 Michel Boucey" + newLine + "Released under 3-Clause BSD License")
fmt.Println("dumber v" + version + " (" + commitShortHash + ")" + newLine + "Copyright © 2021-2024 Michel Boucey" + newLine + "Released under 3-Clause BSD License")
os.Exit(-1)
}

Expand Down

0 comments on commit ca1b0bd

Please sign in to comment.