diff --git a/Makefile b/Makefile index 9f97e0a..8f12219 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,10 @@ VERSION := $(shell git describe --tags --always --dirty) +LDFLAGS := -ldflags "-X 'main.Version=$(VERSION)'" .PHONY: build build: mkdir -p build/$(VERSION) - GOOS=darwin GOARCH=amd64 go build -o build/$(VERSION)/ovpn-auth-darwin-x64 ./cmd/ovpn-auth - GOOS=darwin GOARCH=arm64 go build -o build/$(VERSION)/ovpn-auth-darwin-arm ./cmd/ovpn-auth - GOOS=linux GOARCH=amd64 go build -o build/$(VERSION)/ovpn-auth-linux-x64 ./cmd/ovpn-auth + GOOS=darwin GOARCH=amd64 go build $(LDFLAGS) -o build/$(VERSION)/ovpn-auth-darwin-x64 ./cmd/ovpn-auth + GOOS=darwin GOARCH=arm64 go build $(LDFLAGS) -o build/$(VERSION)/ovpn-auth-darwin-arm ./cmd/ovpn-auth + GOOS=linux GOARCH=amd64 go build $(LDFLAGS) -o build/$(VERSION)/ovpn-auth-linux-x64 ./cmd/ovpn-auth diff --git a/cmd/ovpn-auth/main.go b/cmd/ovpn-auth/main.go index bdbb9bc..a895df8 100644 --- a/cmd/ovpn-auth/main.go +++ b/cmd/ovpn-auth/main.go @@ -22,6 +22,8 @@ import ( "github.com/ufukty/ovpn-auth/internal/register" ) +var Version = "" + func dispatch() error { if len(os.Args) < 2 { return fmt.Errorf("not enough argument") @@ -31,6 +33,8 @@ func dispatch() error { if err := register.WithInteraction(); err != nil { return fmt.Errorf("performing registration interaction: %w", err) } + case "version": + fmt.Println(Version) default: if err := login.WithFile(arg); err != nil { return fmt.Errorf("checking login: %w", err)