mirror of
https://github.com/gesellix/Bose-SoundTouch.git
synced 2026-08-19 00:56:16 +00:00
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)
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user