From 546634572ac9e9aa591ea8c53e3fca155d27baac Mon Sep 17 00:00:00 2001 From: Tobias Gesellchen Date: Sat, 10 Jan 2026 11:58:11 +0100 Subject: [PATCH] feat: implement build-time version injection - Replace hardcoded version with build-time injected variables - Add version, commit, and date variables to main.go with default values - Update Makefile ldflags to use consistent variable names - Add detailed 'version' subcommand showing build info, Go version, and platform - Maintain compatibility with existing release workflow - Support both --version flag (simple) and version subcommand (detailed) --- Makefile | 2 +- cmd/soundtouch-cli/common.go | 12 ++++++++++++ cmd/soundtouch-cli/main.go | 16 +++++++++++++++- 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 8b29403..f63c39d 100644 --- a/Makefile +++ b/Makefile @@ -26,7 +26,7 @@ BUILD_TIME=$(shell date -u '+%Y-%m-%d_%H:%M:%S') COMMIT=$(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown") # Linker flags -LDFLAGS=-X main.Version=$(VERSION) -X main.BuildTime=$(BUILD_TIME) -X main.Commit=$(COMMIT) +LDFLAGS=-X main.version=$(VERSION) -X main.date=$(BUILD_TIME) -X main.commit=$(COMMIT) all: check build diff --git a/cmd/soundtouch-cli/common.go b/cmd/soundtouch-cli/common.go index a77644c..6a9c89f 100644 --- a/cmd/soundtouch-cli/common.go +++ b/cmd/soundtouch-cli/common.go @@ -3,6 +3,7 @@ package main import ( "fmt" "net" + "runtime" "strconv" "strings" "time" @@ -146,3 +147,14 @@ func PrintError(message string) { func PrintWarning(message string) { fmt.Printf("⚠️ %s\n", message) } + +// showVersionInfo displays detailed version information including build details +func showVersionInfo(_ *cli.Context) error { + fmt.Printf("soundtouch-cli version %s\n", version) + fmt.Printf("Build commit: %s\n", commit) + fmt.Printf("Build date: %s\n", date) + fmt.Printf("Go version: %s\n", runtime.Version()) + fmt.Printf("Platform: %s/%s\n", runtime.GOOS, runtime.GOARCH) + + return nil +} diff --git a/cmd/soundtouch-cli/main.go b/cmd/soundtouch-cli/main.go index 8669409..2f2b35a 100644 --- a/cmd/soundtouch-cli/main.go +++ b/cmd/soundtouch-cli/main.go @@ -7,6 +7,13 @@ import ( "github.com/urfave/cli/v2" ) +// Build-time variables injected via ldflags +var ( + version = "dev" + commit = "unknown" + date = "unknown" +) + func main() { app := &cli.App{ Name: "soundtouch-cli", @@ -14,7 +21,7 @@ func main() { Description: `A comprehensive CLI tool for interacting with Bose SoundTouch devices. Supports device discovery, playback control, volume/bass/balance adjustment, source selection, zone management, and more.`, - Version: "1.0.0", + Version: version, Authors: []*cli.Author{ { Name: "SoundTouch CLI Contributors", @@ -23,6 +30,13 @@ func main() { }, Flags: CommonFlags, Commands: []*cli.Command{ + // Version commands + { + Name: "version", + Aliases: []string{"v"}, + Usage: "Show detailed version information", + Action: showVersionInfo, + }, // Discovery commands { Name: "discover",