Skip to content

Commit 8dce388

Browse files
authored
chore: support version flag (#3)
1 parent 476b387 commit 8dce388

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
1+
VERSION ?= $(shell git describe --tags --abbrev=0 2>/dev/null || echo "dev")
2+
COMMIT ?= $(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown")
3+
14
build:
2-
@go build -o keyswift cmd/keyswift/main.go
5+
@go build -ldflags "-X main.version=$(VERSION) -X main.commit=$(COMMIT)" -o keyswift cmd/keyswift/main.go

cmd/keyswift/main.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,23 @@ var (
2525
flagConfig = flag.String("config", "", "Configuration file path (defaults to $XDG_CONFIG_HOME/keyswift/config.js)")
2626
flagVerbose = flag.Bool("verbose", false, "Enable verbose logging")
2727
flagOutputDeviceName = flag.String("output-device-name", "keyswift", "Name of the virtual keyboard device")
28+
flagVersion = flag.Bool("version", false, "Print version information and exit")
29+
)
30+
31+
// These variables are injected at compile time
32+
var (
33+
version = "dev"
34+
commit = "unknown"
2835
)
2936

3037
func main() {
3138
flag.Parse()
3239

40+
if *flagVersion {
41+
fmt.Printf("keyswift version %s (commit: %s)\n", version, commit)
42+
os.Exit(0)
43+
}
44+
3345
// Configure logging
3446
if *flagVerbose {
3547
slog.SetDefault(slog.New(slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{

0 commit comments

Comments
 (0)