[TASK] show version (if available) (#123)
This commit is contained in:
parent
4473b4fca9
commit
50e4dbb75a
@ -7,7 +7,7 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- checkout
|
- checkout
|
||||||
- run: go get -t -d -v ./...
|
- 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:
|
- store_artifacts:
|
||||||
path: /go/bin/
|
path: /go/bin/
|
||||||
destination: yanic
|
destination: yanic
|
||||||
|
25
cmd/version.go
Normal file
25
cmd/version.go
Normal 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)
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user