[TASK] show version (if available) (#123)

This commit is contained in:
Martin/Geno 2018-02-01 16:14:16 +01:00 committed by Geno
parent 4473b4fca9
commit 50e4dbb75a
2 changed files with 26 additions and 1 deletions

View File

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

25
cmd/version.go Normal file
View File

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