add version

This commit is contained in:
Alex Grintsvayg 2018-08-15 10:34:50 -04:00
parent 73f3aceca6
commit 5f9db51d67
4 changed files with 29 additions and 3 deletions

View file

@ -2,9 +2,10 @@ BINARY=prism-bin
DIR = $(shell cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd) DIR = $(shell cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd)
VENDOR_DIR = vendor VENDOR_DIR = vendor
IMPORT_PATH = github.com/lbryio/reflector.go
VERSION = $(shell git --git-dir=${DIR}/.git describe --dirty --always --long --abbrev=7) VERSION = $(shell git --git-dir=${DIR}/.git describe --dirty --always --long --abbrev=7)
LDFLAGS = -ldflags "-X main.Version=${VERSION}" LDFLAGS = -ldflags "-X ${IMPORT_PATH}/meta.Version=${VERSION}"
.PHONY: build dep clean test .PHONY: build dep clean test

View file

@ -58,7 +58,7 @@ var rootCmd = &cobra.Command{
if conf == "" { if conf == "" {
logrus.Errorln("--conf flag required") logrus.Errorln("--conf flag required")
os.Exit(1) os.Exit(1)
} else { } else if conf != "none" {
globalConfig, err = loadConfig(conf) globalConfig, err = loadConfig(conf)
if err != nil { if err != nil {
logrus.Error(err) logrus.Error(err)

22
cmd/version.go Normal file
View file

@ -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)
}

3
meta/meta.go Normal file
View file

@ -0,0 +1,3 @@
package meta
var Version = ""