Skip to content

Commit

Permalink
Show version string with revision
Browse files Browse the repository at this point in the history
  • Loading branch information
dtan4 committed Oct 20, 2016
1 parent 7538c1b commit 9bd6518
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 14 deletions.
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
NAME := ec2c
VERSION := v0.1.0
REVISION := $(shell git rev-parse --short HEAD)
GOVERSION := $(subst go version ,,$(shell go version))

LDFLAGS := -ldflags="-s -w -X \"main.Version=$(VERSION)\" -X \"main.Revision=$(REVISION)\" -X \"main.GoVersion=$(GOVERSION)\""
LDFLAGS := -ldflags="-s -w -X \"main.Version=$(VERSION)\" -X \"main.Revision=$(REVISION)\""

DIST_DIRS := find * -type d -exec

Expand Down
5 changes: 1 addition & 4 deletions command/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ type VersionCommand struct {
func (c *VersionCommand) Run(args []string) int {
var versionString bytes.Buffer

fmt.Fprintf(&versionString, "%s version %s", c.Name, c.Version)
if c.Revision != "" {
fmt.Fprintf(&versionString, " (%s)", c.Revision)
}
fmt.Fprintf(&versionString, "%s version %s, build %s", c.Name, c.Version, c.Revision)

c.Ui.Output(versionString.String())
return 0
Expand Down
2 changes: 1 addition & 1 deletion commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func Commands(meta *command.Meta) map[string]cli.CommandFactory {
return &command.VersionCommand{
Meta: *meta,
Version: Version,
Revision: GitCommit,
Revision: Revision,
Name: Name,
}, nil
},
Expand Down
10 changes: 3 additions & 7 deletions version.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
package main

var (
Name string
Version string
Name = "ec2c"
Version string
Revision string
)

// GitCommit describes latest commit hash.
// This value is extracted by git command when building.
// To set this from outside, use go build -ldflags "-X main.GitCommit \"$(COMMIT)\""
var GitCommit string

0 comments on commit 9bd6518

Please sign in to comment.