Skip to content

Commit

Permalink
Makefile: version number compiled in for --help
Browse files Browse the repository at this point in the history
  • Loading branch information
pda committed Oct 10, 2017
1 parent 6f237e2 commit 951dfa1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
17 changes: 13 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
package = github.com/cultureamp/cfparams
PACKAGE = github.com/cultureamp/cfparams
VERSION = $(shell git describe --tags --candidates=1 --dirty)
FLAGS=-X main.Version=$(VERSION) -s -w

cfparams: main.go
go build -ldflags="$(FLAGS)"

.PHONY: install
install:
go install -ldflags="$(FLAGS)" $(PACKAGE)

.PHONY: release
release: cfparams-darwin-amd64.gz cfparams-linux-amd64.gz
release: cfparams-$(VERSION)-darwin-amd64.gz cfparams-$(VERSION)-linux-amd64.gz

%.gz: %
gzip $<

%-darwin-amd64:
GOOS=darwin GOARCH=amd64 go build -o $@ $(package)
GOOS=darwin GOARCH=amd64 go build -ldflags="$(FLAGS)" -o $@ $(PACKAGE)

%-linux-amd64:
GOOS=linux GOARCH=amd64 go build -o $@ $(package)
GOOS=linux GOARCH=amd64 go build -ldflags="$(FLAGS)" -o $@ $(PACKAGE)
6 changes: 5 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import (
yaml "gopkg.in/yaml.v2"
)

// see Makefile
var Version = "dev"

type Input struct {
TemplateBody []byte
AcceptDefaults bool
Expand Down Expand Up @@ -46,7 +49,8 @@ func main() {
var tplFile, paramFile string

flag.Usage = func() {
fmt.Fprintf(os.Stderr, "\nUsage: %s [flags] [Key=value ...]\n\n", os.Args[0])
fmt.Fprintf(os.Stderr, "cfparams %s\n\n", Version)
fmt.Fprintf(os.Stderr, "Usage: %s [flags] [Key=value ...]\n\n", os.Args[0])
fmt.Fprintf(os.Stderr, "Produces JSON suitable for `aws cloudformation` CLI.\n\n")
flag.PrintDefaults()
}
Expand Down

0 comments on commit 951dfa1

Please sign in to comment.