From 5f9db51d6720a27e9ee60cf69cd508e71bba8232 Mon Sep 17 00:00:00 2001 From: Alex Grintsvayg Date: Wed, 15 Aug 2018 10:34:50 -0400 Subject: [PATCH] add version --- Makefile | 5 +++-- cmd/root.go | 2 +- cmd/version.go | 22 ++++++++++++++++++++++ meta/meta.go | 3 +++ 4 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 cmd/version.go create mode 100644 meta/meta.go diff --git a/Makefile b/Makefile index d743486..74afbf7 100644 --- a/Makefile +++ b/Makefile @@ -2,9 +2,10 @@ BINARY=prism-bin DIR = $(shell cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd) VENDOR_DIR = vendor +IMPORT_PATH = github.com/lbryio/reflector.go -VERSION=$(shell git --git-dir=${DIR}/.git describe --dirty --always --long --abbrev=7) -LDFLAGS = -ldflags "-X main.Version=${VERSION}" +VERSION = $(shell git --git-dir=${DIR}/.git describe --dirty --always --long --abbrev=7) +LDFLAGS = -ldflags "-X ${IMPORT_PATH}/meta.Version=${VERSION}" .PHONY: build dep clean test diff --git a/cmd/root.go b/cmd/root.go index 1a60474..adcb1ac 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -58,7 +58,7 @@ var rootCmd = &cobra.Command{ if conf == "" { logrus.Errorln("--conf flag required") os.Exit(1) - } else { + } else if conf != "none" { globalConfig, err = loadConfig(conf) if err != nil { logrus.Error(err) diff --git a/cmd/version.go b/cmd/version.go new file mode 100644 index 0000000..269ba3d --- /dev/null +++ b/cmd/version.go @@ -0,0 +1,22 @@ +package cmd + +import ( + "log" + + "github.com/lbryio/reflector.go/meta" + + "github.com/spf13/cobra" +) + +func init() { + var cmd = &cobra.Command{ + Use: "version", + Short: "Print the version", + Run: versionCmd, + } + rootCmd.AddCommand(cmd) +} + +func versionCmd(cmd *cobra.Command, args []string) { + log.Printf("version %s\n", meta.Version) +} diff --git a/meta/meta.go b/meta/meta.go new file mode 100644 index 0000000..81f17b6 --- /dev/null +++ b/meta/meta.go @@ -0,0 +1,3 @@ +package meta + +var Version = ""