From 216e59747cd1a99b173cf7fbff5b0dc0d0acfc1a Mon Sep 17 00:00:00 2001 From: Albert S Date: Sun, 16 May 2021 18:38:33 +0200 Subject: [PATCH] Add 'version' command --- Makefile | 6 ++++++ main.go | 5 +++++ 2 files changed, 11 insertions(+) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..da4f847 --- /dev/null +++ b/Makefile @@ -0,0 +1,6 @@ +GIT_COMMIT=$(shell git rev-list -1 HEAD) +GIT_TAG=$(shell git tag --sort="-version:refname" | head -n 1) +all: + go build -ldflags "-X main.GitCommit=${GIT_COMMIT} -X main.GitTag=${GIT_TAG}" + + diff --git a/main.go b/main.go index 99c781e..e969739 100644 --- a/main.go +++ b/main.go @@ -27,6 +27,9 @@ type HistoryEntry struct { timestamp time.Time } +var GitTag string +var GitCommit string + func databaseLocation() string { envOverride := os.Getenv("HS9001_DB_PATH") if envOverride != "" { @@ -354,6 +357,8 @@ func main() { os.Exit(23) case "import": importFromStdin(conn) + case "version": + fmt.Fprintf(os.Stdout, "Git Tag: %s\nGit Commit: %s\n", GitTag, GitCommit) default: fmt.Fprintf(os.Stderr, "Error: Unknown subcommand '%s' supplied\n\n", cmd) printUsage()