Skip to content

Commit

Permalink
Add application version support
Browse files Browse the repository at this point in the history
  • Loading branch information
Praveen Premaratne committed Mar 7, 2020
1 parent ef142d1 commit 7285e03
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
4 changes: 1 addition & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ TEST_REPORT = tests.xml
GOARCH = amd64

VERSION?=?
COMMIT=\$(shell git rev-parse HEAD)
BRANCH=\$(shell git rev-parse --abbrev-ref HEAD)

# Symlink into GOPATH
GITHUB_USERNAME=praveenprem
Expand All @@ -15,7 +13,7 @@ CURRENT_DIR=\$(shell pwd)
BUILD_DIR_LINK=\$(shell readlink ${BUILD_DIR})

# Setup the -ldflags option for go build here, interpolate the variable values
LDFLAGS = -ldflags "-X main.VERSION=${VERSION} -X main.COMMIT=${COMMIT} -X main.BRANCH=${BRANCH}"
LDFLAGS = -ldflags "-X main.VERSION=${VERSION}"

# Build the project
all: link clean test vet linux darwin windows
Expand Down
6 changes: 6 additions & 0 deletions argparse.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func (app *App) Parser() {
" -history and -d are also available")
flag.BoolVar(&app.History, "history", false, "HELP: Print the timesheet of the day")
flag.BoolVar(&app.PrintWeek, "week", false, "HELP: Print timesheet of the current week")
flag.BoolVar(&app.Version, "v", false, "Print application version")
flag.Parse()
app.validate()
}
Expand All @@ -60,6 +61,11 @@ func (app *App) validate() {
app.usage()
}

if app.Version {
fmt.Println(VERSION)
os.Exit(0)
}

if app.TimeRemaining || app.PrintWeek {
return
}
Expand Down
3 changes: 3 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type App struct {
TimeRemaining bool
History bool
PrintWeek bool
Version bool
Configuration struct {
Auth string
Domain string
Expand All @@ -49,6 +50,8 @@ type Application interface {
GetWeekTimesheet(domain string, auth string)
}

var VERSION string

func main() {
var app App

Expand Down

0 comments on commit 7285e03

Please sign in to comment.