/
version.go
58 lines (50 loc) · 1.26 KB
/
version.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package cmd
import (
"encoding/json"
"fmt"
"runtime"
"github.com/spf13/cobra"
"gopkg.in/yaml.v2"
)
var (
// Version defines the application version (defined at compile time)
Version = ""
// Commit defines the application commit hash (defined at compile time)
Commit = ""
// SDKCommit defines the CosmosSDK commit hash (defined at compile time)
SDKCommit = ""
)
type versionInfo struct {
Version string `json:"version" yaml:"version"`
Commit string `json:"commit" yaml:"commit"`
CosmosSDK string `json:"cosmos-sdk" yaml:"cosmos-sdk"`
Go string `json:"go" yaml:"go"`
}
func getVersionCmd() *cobra.Command {
versionCmd := &cobra.Command{
Use: "version",
Aliases: []string{"v"},
Short: "Print relayer version info",
RunE: func(cmd *cobra.Command, args []string) error {
jsn, err := cmd.Flags().GetBool(flagJSON)
if err != nil {
return err
}
verInfo := versionInfo{
Version: Version,
Commit: Commit,
CosmosSDK: SDKCommit,
Go: fmt.Sprintf("%s %s/%s", runtime.Version(), runtime.GOOS, runtime.GOARCH),
}
var bz []byte
if jsn {
bz, err = json.Marshal(verInfo)
} else {
bz, err = yaml.Marshal(&verInfo)
}
fmt.Println(string(bz))
return err
},
}
return jsonFlag(versionCmd)
}