diff --git a/Makefile b/Makefile index 8fac9fac4..2c7cb4f92 100644 --- a/Makefile +++ b/Makefile @@ -1,13 +1,15 @@ +VERSION := $(shell git describe --tags) run: go run . build: + @echo "Version: " $(VERSION) -mkdir build - cd build; GOOS=linux GOARCH=arm go build -o gdu-linux-arm ..; tar czf gdu-linux-arm.tgz gdu-linux-arm - cd build; GOOS=linux GOARCH=amd64 go build -o gdu-linux-amd64 ..; tar czf gdu-linux-amd64.tgz gdu-linux-amd64 - cd build; GOOS=windows GOARCH=amd64 go build -o gdu-windows-amd64.exe ..; zip gdu-windows-amd64.zip gdu-windows-amd64.exe - cd build; GOOS=darwin GOARCH=amd64 go build -o gdu-darwin-amd64 ..; tar czf gdu-darwin-amd64.tgz gdu-darwin-amd64 + cd build; GOOS=linux GOARCH=arm go build -ldflags="-s -w -X 'main.AppVersion=$(VERSION)'" -o gdu-linux-arm ..; tar czf gdu-linux-arm.tgz gdu-linux-arm + cd build; GOOS=linux GOARCH=amd64 go build -ldflags="-s -w -X 'main.AppVersion=$(VERSION)'" -o gdu-linux-amd64 ..; tar czf gdu-linux-amd64.tgz gdu-linux-amd64 + cd build; GOOS=windows GOARCH=amd64 go build -ldflags="-s -w -X 'main.AppVersion=$(VERSION)'" -o gdu-windows-amd64.exe ..; zip gdu-windows-amd64.zip gdu-windows-amd64.exe + cd build; GOOS=darwin GOARCH=amd64 go build -ldflags="-s -w -X 'main.AppVersion=$(VERSION)'" -o gdu-darwin-amd64 ..; tar czf gdu-darwin-amd64.tgz gdu-darwin-amd64 test: go test -v diff --git a/main.go b/main.go index 6d2391b86..ba282d260 100644 --- a/main.go +++ b/main.go @@ -2,6 +2,7 @@ package main import ( "flag" + "fmt" "log" "os" "runtime" @@ -9,10 +10,19 @@ import ( "github.com/gdamore/tcell/v2" ) +// AppVersion stores the current version of the app +var AppVersion = "development" + func main() { logFile := flag.String("log-file", "/dev/null", "Path to a logfile") + showVersion := flag.Bool("v", false, "Prints version") flag.Parse() + if *showVersion { + fmt.Println("Version:\t", AppVersion) + return + } + f, err := os.OpenFile(*logFile, os.O_RDWR|os.O_CREATE, 0644) if err != nil { log.Fatalf("error opening file: %v", err)