Skip to content

Commit

Permalink
added resolver for version flag and also added help section for makef…
Browse files Browse the repository at this point in the history
…ile, version and build date injection
  • Loading branch information
joicemjoseph committed Oct 1, 2020
1 parent f4d87da commit 5e0777c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
15 changes: 14 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
BIN := $(shell basename $$PWD)
HASH := $(shell git rev-parse HEAD | cut -c 1-8)
COMMIT_DATE := $(shell git show -s --format=%ci ${HASH})
BUILD_DATE := $(shell date '+%Y-%m-%d %H:%M:%S')
VERSION := ${HASH} (${COMMIT_DATE})

STATIC := config.toml.sample schema.sql queries.sql

# Install dependencies needed for building
Expand All @@ -7,7 +13,7 @@ deps:

.PHONY: build
build:
go build -o dictmaker
go build -o ${BIN} -ldflags="-X 'main.buildVersion=${VERSION}' -X 'main.buildDate=${BUILD_DATE}'"
stuffbin -a stuff -in dictmaker -out dictmaker ${STATIC}

.PHONY: build-tokenizers
Expand All @@ -21,3 +27,10 @@ build-tokenizers:
.PHONY: pack-releases
pack-releases:
$(foreach var,$(RELEASE_BUILDS),stuffbin -a stuff -in ${var} -out ${var} ${STATIC} $(var);)

# Absolutely awesome: http://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
.PHONY: help
help:
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

.DEFAULT_GOAL := build
10 changes: 10 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ import (
flag "github.com/spf13/pflag"
)

var (
buildVersion = "unknown"
buildDate = "unknown"
)

// Lang represents a language's configuration.
type Lang struct {
Name string `koanf:"name"`
Expand Down Expand Up @@ -96,6 +101,11 @@ func init() {
if err := ko.Load(posflag.Provider(f, ".", ko), nil); err != nil {
logger.Fatalf("error loading config: %v", err)
}

if ko.Bool("version") {
fmt.Printf("Commit: %v\nBuild: %v\n", buildVersion, buildDate)
os.Exit(0)
}
}

func main() {
Expand Down

0 comments on commit 5e0777c

Please sign in to comment.