diff --git a/Makefile b/Makefile index baf1d56..56320b9 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,11 @@ BINARY_NAME := brew-sync GO := go GOFLAGS := -LDFLAGS := + +# Version info injected at build time +VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo dev) +COMMIT := $(shell git rev-parse --short HEAD 2>/dev/null || echo unknown) +LDFLAGS := -X brew-sync/cmd.Version=$(VERSION) -X brew-sync/cmd.Commit=$(COMMIT) # Build output directory BUILD_DIR := build diff --git a/cmd/root.go b/cmd/root.go index b97c2c0..a9e9584 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -12,6 +12,12 @@ import ( "github.com/spf13/cobra" ) +// Version info set via ldflags at build time. +var ( + Version = "dev" + Commit = "unknown" +) + var ( // Global flag values accessible by subcommands. cfgFile string @@ -107,8 +113,9 @@ func getUpdatedBy() string { } var rootCmd = &cobra.Command{ - Use: "brew-sync", - Short: "Synchronize Homebrew packages across machines", + Use: "brew-sync", + Short: "Synchronize Homebrew packages across machines", + Version: Version + " (" + Commit + ")", Long: `brew-sync is a CLI tool that wraps Homebrew to synchronize installed packages (formulae and casks) across multiple machines.