Skip to content

Commit 5aa4dd2

Browse files
committed
feat(cli): add git commit hash to version output
Users can now see the exact git commit used to build the binary, which helps with debugging and deployment tracking.
1 parent 7fa70b8 commit 5aa4dd2

2 files changed

Lines changed: 21 additions & 6 deletions

File tree

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ MAIN_GO=$(CMD_DIR)/main.go
88

99
# Version
1010
VERSION?=$(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
11+
GIT_COMMIT=$(shell git rev-parse --short=8 HEAD 2>/dev/null || echo "unknown")
1112
BUILD_TIME=$(shell date +%FT%T%z)
1213
GO_VERSION=$(shell $(GO) version | awk '{print $$3}')
13-
LDFLAGS=-ldflags "-X main.version=$(VERSION) -X main.buildTime=$(BUILD_TIME) -X main.goVersion=$(GO_VERSION)"
14+
LDFLAGS=-ldflags "-X main.version=$(VERSION) -X main.gitCommit=$(GIT_COMMIT) -X main.buildTime=$(BUILD_TIME) -X main.goVersion=$(GO_VERSION)"
1415

1516
# Go variables
1617
GO?=go

cmd/picoclaw/main.go

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,20 @@ import (
3535
)
3636

3737
var (
38-
version = "dev"
39-
buildTime string
40-
goVersion string
38+
version = "dev"
39+
gitCommit string
40+
buildTime string
41+
goVersion string
4142
)
4243

4344
const logo = "🦞"
4445

4546
func printVersion() {
46-
fmt.Printf("%s picoclaw %s\n", logo, version)
47+
fmt.Printf("%s picoclaw %s", logo, version)
48+
if gitCommit != "" {
49+
fmt.Printf(" (git: %s)", gitCommit)
50+
}
51+
fmt.Println()
4752
if buildTime != "" {
4853
fmt.Printf(" Build: %s\n", buildTime)
4954
}
@@ -760,7 +765,16 @@ func statusCmd() {
760765

761766
configPath := getConfigPath()
762767

763-
fmt.Printf("%s picoclaw Status\n\n", logo)
768+
fmt.Printf("%s picoclaw Status\n", logo)
769+
fmt.Printf("Version: %s", version)
770+
if gitCommit != "" {
771+
fmt.Printf(" (git: %s)", gitCommit)
772+
}
773+
fmt.Println()
774+
if buildTime != "" {
775+
fmt.Printf("Build: %s\n", buildTime)
776+
}
777+
fmt.Println()
764778

765779
if _, err := os.Stat(configPath); err == nil {
766780
fmt.Println("Config:", configPath, "✓")

0 commit comments

Comments
 (0)