Skip to content

Commit f59ee69

Browse files
committed
Read binary version using BuildInfo
1 parent 83ccfb9 commit f59ee69

File tree

3 files changed

+7
-15
lines changed

3 files changed

+7
-15
lines changed

Makefile

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,10 @@
11
OUT_DIR := ./out
22
GO_FILES := $(shell find . -type f \( -iname '*.go' \))
33

4-
PBCLI_BUILD_VERSION ?= $(shell git describe --tags)
5-
ifeq ($(PBCLI_BUILD_VERSION),)
6-
_ := $(error Cannot determine build version)
7-
endif
8-
9-
BUILD_VERSION_FLAG := github.com/pushbits/cli/internal/buildconfig.Version=$(PBCLI_BUILD_VERSION)
10-
114
.PHONY: build
125
build:
136
mkdir -p $(OUT_DIR)
14-
go build -ldflags "-w -s -X $(BUILD_VERSION_FLAG)" -o $(OUT_DIR)/pbcli ./cmd/pbcli
7+
go build -ldflags "-w -s" -o $(OUT_DIR)/pbcli ./cmd/pbcli
158

169
.PHONY: clean
1710
clean:

internal/buildconfig/buildconfig.go

Lines changed: 0 additions & 5 deletions
This file was deleted.

internal/commands/version.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ package commands
33

44
import (
55
"fmt"
6+
"runtime/debug"
67

7-
"github.com/pushbits/cli/internal/buildconfig"
88
"github.com/pushbits/cli/internal/options"
99
)
1010

@@ -13,7 +13,11 @@ type VersionCommand struct{}
1313

1414
// Run is the function for the version command.
1515
func (*VersionCommand) Run(_ *options.Options) error {
16-
fmt.Printf("pbcli %s\n", buildconfig.Version)
16+
buildInfo, ok := debug.ReadBuildInfo()
17+
if !ok {
18+
return fmt.Errorf("build info not available")
19+
}
1720

21+
fmt.Printf("pbcli %s\n", buildInfo.Main.Version)
1822
return nil
1923
}

0 commit comments

Comments
 (0)