Skip to content

Commit

Permalink
#4 - version details
Browse files Browse the repository at this point in the history
  • Loading branch information
g4s8 committed Jan 5, 2019
1 parent 0270472 commit a80cccf
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ before:
builds:
- env:
- CGO_ENABLED=0
- ldflags:
- -X "main.buildVersion={{.Env.TRAVIS_TAG}}{{.Env.TRAVIS_BUILD_NUMBER}}" -X "main.buildCommit={{.Env.TRAVIS_COMMIT}}"
archive:
replacements:
darwin: Darwin
Expand Down
26 changes: 26 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
OUTPUT?=gitstrap
BUILD_VERSION?=0.0
BUILD_HASH?=stub
BUILD_DATE?=2019.01.01

all: clean build test lint

build: $(OUTPUT)


$(OUTPUT):
go build \
-ldflags "-X main.buildVersion=$(BUILD_VERSION) -X main.buildCommit=$(BUILD_HASH) -X main.buildDate=$(BUILD_DATE)" \
-o $(OUTPUT)

clean:
rm -f $(OUTPUT)

test: $(OUTPUT)
go test .

lint: $(OUTPUT)
gometalinter .

.PHONY: build clean test lint

19 changes: 15 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,28 @@ import (
)

var (
token string
conf *cfg.YamlConfig
ctx context.Context
cli *github.Client
token string
conf *cfg.YamlConfig
ctx context.Context
cli *github.Client
buildVersion string
buildCommit string
buildDate string
)

func main() {
var config string
var flagVersion bool
flag.StringVar(&token, "token", "", "Github API token")
flag.StringVar(&config, "config", ".gitstrap.yaml", "Gitstrap config (default .gitstrap)")
flag.BoolVar(&flagVersion, "version", false, "Show version")
flag.Parse()
if flagVersion {
fmt.Printf("gitstrap version: %s\n"+
"commit hash: %s\n"+
"build date: %s\n", buildVersion, buildCommit, buildDate)
os.Exit(0)
}
if token == "" {
flagErr("Github token required")
}
Expand Down

0 comments on commit a80cccf

Please sign in to comment.