From 5aa4dd29756df87b7430a0ee5c417924c54e362f Mon Sep 17 00:00:00 2001 From: yinwm Date: Fri, 13 Feb 2026 16:39:44 +0800 Subject: [PATCH] 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. --- Makefile | 3 ++- cmd/picoclaw/main.go | 24 +++++++++++++++++++----- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index c9af7d5..0025ef4 100644 --- a/Makefile +++ b/Makefile @@ -8,9 +8,10 @@ MAIN_GO=$(CMD_DIR)/main.go # Version VERSION?=$(shell git describe --tags --always --dirty 2>/dev/null || echo "dev") +GIT_COMMIT=$(shell git rev-parse --short=8 HEAD 2>/dev/null || echo "unknown") BUILD_TIME=$(shell date +%FT%T%z) GO_VERSION=$(shell $(GO) version | awk '{print $$3}') -LDFLAGS=-ldflags "-X main.version=$(VERSION) -X main.buildTime=$(BUILD_TIME) -X main.goVersion=$(GO_VERSION)" +LDFLAGS=-ldflags "-X main.version=$(VERSION) -X main.gitCommit=$(GIT_COMMIT) -X main.buildTime=$(BUILD_TIME) -X main.goVersion=$(GO_VERSION)" # Go variables GO?=go diff --git a/cmd/picoclaw/main.go b/cmd/picoclaw/main.go index 8c00110..694a011 100644 --- a/cmd/picoclaw/main.go +++ b/cmd/picoclaw/main.go @@ -35,15 +35,20 @@ import ( ) var ( - version = "dev" - buildTime string - goVersion string + version = "dev" + gitCommit string + buildTime string + goVersion string ) const logo = "🦞" func printVersion() { - fmt.Printf("%s picoclaw %s\n", logo, version) + fmt.Printf("%s picoclaw %s", logo, version) + if gitCommit != "" { + fmt.Printf(" (git: %s)", gitCommit) + } + fmt.Println() if buildTime != "" { fmt.Printf(" Build: %s\n", buildTime) } @@ -760,7 +765,16 @@ func statusCmd() { configPath := getConfigPath() - fmt.Printf("%s picoclaw Status\n\n", logo) + fmt.Printf("%s picoclaw Status\n", logo) + fmt.Printf("Version: %s", version) + if gitCommit != "" { + fmt.Printf(" (git: %s)", gitCommit) + } + fmt.Println() + if buildTime != "" { + fmt.Printf("Build: %s\n", buildTime) + } + fmt.Println() if _, err := os.Stat(configPath); err == nil { fmt.Println("Config:", configPath, "✓")