bookends

commit 250bbe0eacf418682c515251bc4884261d3d958b

Author: Honza Pokorny <honza@redhat.com>

Implement version command

 Makefile | 6 ++++--
 cmd/root.go | 2 +-
 cmd/version.go | 37 +++++++++++++++++++++++++++++++++++++


diff --git a/Makefile b/Makefile
index f8597ac3d11ebdca2416932167d3db2287da4d8e..5da8634481bcfea930b98c05932321fc00ff7862 100644
--- a/Makefile
+++ b/Makefile
@@ -1,3 +1,5 @@
+BUILD_VERSION ?= $(shell git describe --always --abbrev=40 --dirty)
+LDFLAGS="-X git.pokorny.ca/bookends/cmd.BookendsVersion=${BUILD_VERSION}"
+
 all:
-	go run main.go build
-	go run main.go cache
+	go build -ldflags $(LDFLAGS) -o bookends main.go




diff --git a/cmd/root.go b/cmd/root.go
index e4e063f2cb8d026e40ad5aaddd91d5549565dc42..0934acc2151c550d43a2bf2434b19464983fb487 100644
--- a/cmd/root.go
+++ b/cmd/root.go
@@ -54,5 +54,5 @@ 	rootCmd.PersistentFlags().StringVar(&templateFilename, "template-filename", "template.html", "")
 
 	rootCmd.AddCommand(buildCmd)
 	rootCmd.AddCommand(cacheCovers)
-	// rootCmd.AddCommand(versionCmd)
+	rootCmd.AddCommand(versionCmd)
 }




diff --git a/cmd/version.go b/cmd/version.go
new file mode 100644
index 0000000000000000000000000000000000000000..8fa47e83fc9b9a78a51c0c967b77550a0abee3df
--- /dev/null
+++ b/cmd/version.go
@@ -0,0 +1,37 @@
+// bookends
+// Copyright (C) 2021   Honza Pokorny <honza@pokorny.ca>
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program.  If not, see <https://www.gnu.org/licenses/>.
+
+package cmd
+
+import (
+	"fmt"
+
+	"github.com/spf13/cobra"
+)
+
+var BookendsVersion string
+
+var versionCmd = &cobra.Command{
+	Use:   "version",
+	Short: "Show bookends version",
+	Run: func(cmd *cobra.Command, args []string) {
+		if BookendsVersion == "" {
+			fmt.Println("dev")
+			return
+		}
+		fmt.Println(BookendsVersion)
+	},
+}