diff --git a/Makefile b/Makefile index 57c1dbf..2611e4d 100644 --- a/Makefile +++ b/Makefile @@ -1,2 +1,5 @@ +VERSION ?= $(shell git describe --tags --abbrev=0 2>/dev/null || echo "dev") +COMMIT ?= $(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown") + build: - @go build -o keyswift cmd/keyswift/main.go \ No newline at end of file + @go build -ldflags "-X main.version=$(VERSION) -X main.commit=$(COMMIT)" -o keyswift cmd/keyswift/main.go \ No newline at end of file diff --git a/cmd/keyswift/main.go b/cmd/keyswift/main.go index ad0c337..400faa6 100644 --- a/cmd/keyswift/main.go +++ b/cmd/keyswift/main.go @@ -25,11 +25,23 @@ var ( flagConfig = flag.String("config", "", "Configuration file path (defaults to $XDG_CONFIG_HOME/keyswift/config.js)") flagVerbose = flag.Bool("verbose", false, "Enable verbose logging") flagOutputDeviceName = flag.String("output-device-name", "keyswift", "Name of the virtual keyboard device") + flagVersion = flag.Bool("version", false, "Print version information and exit") +) + +// These variables are injected at compile time +var ( + version = "dev" + commit = "unknown" ) func main() { flag.Parse() + if *flagVersion { + fmt.Printf("keyswift version %s (commit: %s)\n", version, commit) + os.Exit(0) + } + // Configure logging if *flagVerbose { slog.SetDefault(slog.New(slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{