Add --version / version with baked-in git commit
ldflags inject version, commit, and build date; a version subcommand also reports go version and platform. Ends the which-binary-is-this guessing after deploys. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
10
Makefile
10
Makefile
@@ -1,7 +1,15 @@
|
|||||||
BINARY := rtsp-streamer
|
BINARY := rtsp-streamer
|
||||||
PKG := ./cmd/rtsp-streamer
|
PKG := ./cmd/rtsp-streamer
|
||||||
BINDIR := bin
|
BINDIR := bin
|
||||||
LDFLAGS := -s -w
|
|
||||||
|
# Build metadata baked into the binary (see `rtsp-streamer version`).
|
||||||
|
VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo dev)
|
||||||
|
COMMIT ?= $(shell git rev-parse --short HEAD 2>/dev/null || echo none)
|
||||||
|
DATE ?= $(shell date -u +%Y-%m-%dT%H:%M:%SZ)
|
||||||
|
LDFLAGS := -s -w \
|
||||||
|
-X main.version=$(VERSION) \
|
||||||
|
-X main.commit=$(COMMIT) \
|
||||||
|
-X main.date=$(DATE)
|
||||||
|
|
||||||
# Install location. Override with `make install PREFIX=/opt`.
|
# Install location. Override with `make install PREFIX=/opt`.
|
||||||
PREFIX ?= /usr/local
|
PREFIX ?= /usr/local
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
|
"runtime"
|
||||||
"sort"
|
"sort"
|
||||||
"syscall"
|
"syscall"
|
||||||
"text/tabwriter"
|
"text/tabwriter"
|
||||||
@@ -17,6 +18,21 @@ import (
|
|||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// versionCmd prints detailed build and runtime info.
|
||||||
|
func versionCmd() *cobra.Command {
|
||||||
|
return &cobra.Command{
|
||||||
|
Use: "version",
|
||||||
|
Short: "Print version, git commit, and build info",
|
||||||
|
Run: func(cmd *cobra.Command, _ []string) {
|
||||||
|
fmt.Printf("rtsp-streamer %s\n", version)
|
||||||
|
fmt.Printf(" commit: %s\n", commit)
|
||||||
|
fmt.Printf(" built: %s\n", date)
|
||||||
|
fmt.Printf(" go: %s\n", runtime.Version())
|
||||||
|
fmt.Printf(" platform: %s/%s\n", runtime.GOOS, runtime.GOARCH)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// daemonCmd runs the video wall. This is what systemd (via sway) launches.
|
// daemonCmd runs the video wall. This is what systemd (via sway) launches.
|
||||||
func daemonCmd() *cobra.Command {
|
func daemonCmd() *cobra.Command {
|
||||||
return &cobra.Command{
|
return &cobra.Command{
|
||||||
|
|||||||
@@ -17,10 +17,18 @@ var (
|
|||||||
logLevel string
|
logLevel string
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Build metadata, injected via -ldflags -X at build time (see Makefile).
|
||||||
|
var (
|
||||||
|
version = "dev"
|
||||||
|
commit = "none"
|
||||||
|
date = "unknown"
|
||||||
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
root := &cobra.Command{
|
root := &cobra.Command{
|
||||||
Use: "rtsp-streamer",
|
Use: "rtsp-streamer",
|
||||||
Short: "Full-screen RTSP camera wall for UniFi Protect",
|
Short: "Full-screen RTSP camera wall for UniFi Protect",
|
||||||
|
Version: fmt.Sprintf("%s (commit %s, built %s)", version, commit, date),
|
||||||
SilenceUsage: true,
|
SilenceUsage: true,
|
||||||
SilenceErrors: true,
|
SilenceErrors: true,
|
||||||
}
|
}
|
||||||
@@ -34,6 +42,7 @@ func main() {
|
|||||||
statusCmd(),
|
statusCmd(),
|
||||||
tuiCmd(),
|
tuiCmd(),
|
||||||
configCmd(),
|
configCmd(),
|
||||||
|
versionCmd(),
|
||||||
)
|
)
|
||||||
|
|
||||||
if err := root.Execute(); err != nil {
|
if err := root.Execute(); err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user