Skip to content

Commit

Permalink
Merge pull request #10 from hidapple/version-print-commit-no
Browse files Browse the repository at this point in the history
update: print git commit number by version option
  • Loading branch information
hidapple authored Mar 11, 2018
2 parents fa8ae50 + a8f1dbf commit 423774d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
COMMIT = $$(git describe --always)

BUILD_FLAGS = -ldflags "-X main.Commit=\"$(COMMIT)\""
BUILD_FLAGS = -ldflags "-X main.Commit=$(COMMIT)"

test:
@echo "===> Running tests..."
Expand All @@ -13,7 +13,11 @@ build:
cross-build:
@echo "===> Building for cross platform..."
@rm -rf ./dist
@gox -os="linux darwin windows" -arch="386 amd64" -output "dist/isbn-gen_{{.OS}}_{{.Arch}}"
@gox\
-os="linux darwin windows"\
-arch="386 amd64"\
-ldflags="$(COMMIT)"\
-output "dist/isbn-gen_{{.OS}}_{{.Arch}}"

install:
@echo "===> Installing isbn-gen in $(GOPATH)/bin directory..."
Expand Down
2 changes: 1 addition & 1 deletion cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (cli *CLI) Run(args []string) int {

// Show version
if version {
fmt.Fprintf(cli.errStream, "%s version %s\n", Name, Version)
fmt.Fprintf(cli.errStream, "%s version %s (%s)\n", Name, Version, Commit)
return ExitCodeOK
}

Expand Down
2 changes: 1 addition & 1 deletion cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func TestRun_versionFlag(t *testing.T) {
t.Fatalf("Expected exit code is %d but was %d", ExitCodeOK, status)
}

expected := fmt.Sprintf("isbn-gen version %s", Version)
expected := fmt.Sprintf("isbn-gen version %s (%s)", Version, Commit)
if !strings.Contains(errStream.String(), expected) {
t.Fatalf("Expected output contain %q but was %q", expected, errStream.String())
}
Expand Down

0 comments on commit 423774d

Please sign in to comment.