Skip to content

Commit 11bf55a

Browse files
committed
Add a --version option to display the version of git-sizer
1 parent 9f616f7 commit 11bf55a

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ export GOPATH
66
GO := $(CURDIR)/script/go
77
GOFMT := $(CURDIR)/script/gofmt
88

9-
GO_LDFLAGS := -X main.BuildVersion=$(shell git rev-parse HEAD)
10-
GO_LDFLAGS += -X main.BuildDescribe=$(shell git describe --tags --always --dirty)
9+
GO_LDFLAGS := -X main.BuildVersion=$(shell git describe --tags --always --dirty || echo unknown)
1110
GOFLAGS := -ldflags "$(GO_LDFLAGS)"
1211

1312
ifdef USE_ISATTY
@@ -52,7 +51,8 @@ define PLATFORM_template =
5251
.PHONY: bin/git-sizer-$(1)-$(2)$(3)
5352
bin/git-sizer-$(1)-$(2)$(3):
5453
mkdir -p bin
55-
cd $$(GOPATH)/src/$$(PACKAGE) && GOOS=$(1) GOARCH=$(2) $$(GO) build $$(GOFLAGS) -o $$(ROOTDIR)/$$@ $$(PACKAGE)
54+
cd $$(GOPATH)/src/$$(PACKAGE) && \
55+
GOOS=$(1) GOARCH=$(2) $$(GO) build $$(GOFLAGS) -ldflags "-X main.ReleaseVersion=$$(VERSION)" -o $$(ROOTDIR)/$$@ $$(PACKAGE)
5656
common-platforms: bin/git-sizer-$(1)-$(2)$(3)
5757

5858
# Note that releases don't include code from vendor (they're only used

git-sizer.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ import (
1616
"github.com/spf13/pflag"
1717
)
1818

19+
var ReleaseVersion string
20+
var BuildVersion string
21+
1922
type NegatedBoolValue struct {
2023
value *bool
2124
}
@@ -59,6 +62,7 @@ func mainImplementation() error {
5962
var jsonOutput bool
6063
var threshold sizes.Threshold = 1
6164
var progress bool
65+
var version bool
6266

6367
pflag.BoolVar(&processBranches, "branches", false, "process all branches")
6468
pflag.BoolVar(&processTags, "tags", false, "process all tags")
@@ -97,6 +101,7 @@ func mainImplementation() error {
97101
atty = false
98102
}
99103
pflag.BoolVar(&progress, "progress", atty, "report progress to stderr")
104+
pflag.BoolVar(&version, "version", false, "report the git-sizer version number")
100105
pflag.Var(&NegatedBoolValue{&progress}, "no-progress", "suppress progress output")
101106
pflag.Lookup("no-progress").NoOptDefVal = "true"
102107

@@ -116,6 +121,15 @@ func mainImplementation() error {
116121
defer pprof.StopCPUProfile()
117122
}
118123

124+
if version {
125+
if ReleaseVersion != "" {
126+
fmt.Printf("git-sizer release %s\n", ReleaseVersion)
127+
} else {
128+
fmt.Printf("git-sizer build %s\n", BuildVersion)
129+
}
130+
return nil
131+
}
132+
119133
args := pflag.Args()
120134

121135
if len(args) != 0 {

0 commit comments

Comments
 (0)