From 50e4dbb75a14332e681bf32236fb6f9ed87c232a Mon Sep 17 00:00:00 2001 From: Martin/Geno Date: Thu, 1 Feb 2018 16:14:16 +0100 Subject: [PATCH] [TASK] show version (if available) (#123) --- circle.yml | 2 +- cmd/version.go | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 cmd/version.go diff --git a/circle.yml b/circle.yml index 8bed18b..f915c43 100644 --- a/circle.yml +++ b/circle.yml @@ -7,7 +7,7 @@ jobs: steps: - checkout - run: go get -t -d -v ./... - - run: go install github.com/FreifunkBremen/yanic + - run: go install -ldflags "-X github.com/FreifunkBremen/yanic/cmd.VERSION=`git -C $GOPATH/src/github.com/FreifunkBremen/yanic rev-parse HEAD`" github.com/FreifunkBremen/yanic - store_artifacts: path: /go/bin/ destination: yanic diff --git a/cmd/version.go b/cmd/version.go new file mode 100644 index 0000000..3c8683d --- /dev/null +++ b/cmd/version.go @@ -0,0 +1,25 @@ +package cmd + +import ( + "fmt" + + "github.com/spf13/cobra" +) + +var VERSION string + +// versionCMD to print version +var versionCMD = &cobra.Command{ + Use: "version", + Short: "print version of yanic", + Run: func(cmd *cobra.Command, args []string) { + + fmt.Printf("yanic version: %s\n", VERSION) + }, +} + +func init() { + if VERSION != "" { + RootCmd.AddCommand(versionCMD) + } +}