Skip to content

Commit

Permalink
Merge pull request #37 from github/release-version
Browse files Browse the repository at this point in the history
Add a `--version` option to display the version of `git-sizer`
  • Loading branch information
mhagger authored Apr 12, 2018
2 parents 9f616f7 + 11bf55a commit d4e7e53
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ export GOPATH
GO := $(CURDIR)/script/go
GOFMT := $(CURDIR)/script/gofmt

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

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

# Note that releases don't include code from vendor (they're only used
Expand Down
14 changes: 14 additions & 0 deletions git-sizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ import (
"github.com/spf13/pflag"
)

var ReleaseVersion string
var BuildVersion string

type NegatedBoolValue struct {
value *bool
}
Expand Down Expand Up @@ -59,6 +62,7 @@ func mainImplementation() error {
var jsonOutput bool
var threshold sizes.Threshold = 1
var progress bool
var version bool

pflag.BoolVar(&processBranches, "branches", false, "process all branches")
pflag.BoolVar(&processTags, "tags", false, "process all tags")
Expand Down Expand Up @@ -97,6 +101,7 @@ func mainImplementation() error {
atty = false
}
pflag.BoolVar(&progress, "progress", atty, "report progress to stderr")
pflag.BoolVar(&version, "version", false, "report the git-sizer version number")
pflag.Var(&NegatedBoolValue{&progress}, "no-progress", "suppress progress output")
pflag.Lookup("no-progress").NoOptDefVal = "true"

Expand All @@ -116,6 +121,15 @@ func mainImplementation() error {
defer pprof.StopCPUProfile()
}

if version {
if ReleaseVersion != "" {
fmt.Printf("git-sizer release %s\n", ReleaseVersion)
} else {
fmt.Printf("git-sizer build %s\n", BuildVersion)
}
return nil
}

args := pflag.Args()

if len(args) != 0 {
Expand Down

0 comments on commit d4e7e53

Please sign in to comment.