-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
version.go
74 lines (64 loc) · 1.57 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package cmd
import (
"encoding/json"
"fmt"
"runtime"
"runtime/debug"
"strings"
"github.com/spf13/cobra"
"gopkg.in/yaml.v3"
)
var (
// Version defines the application version (defined at compile time)
Version = ""
// Commit defines the application commit hash (defined at compile time)
Commit = ""
)
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(a *appState) *cobra.Command {
versionCmd := &cobra.Command{
Use: "version",
Aliases: []string{"v"},
Short: "Print the relayer version info",
Example: strings.TrimSpace(fmt.Sprintf(`
$ %s version --json
$ %s v`,
appName, appName,
)),
RunE: func(cmd *cobra.Command, args []string) error {
jsn, err := cmd.Flags().GetBool(flagJSON)
if err != nil {
return err
}
cosmosSDK := "(unable to determine)"
if bi, ok := debug.ReadBuildInfo(); ok {
for _, dep := range bi.Deps {
if dep.Path == "github.com/cosmos/cosmos-sdk" {
cosmosSDK = dep.Version
break
}
}
}
verInfo := versionInfo{
Version: Version,
Commit: Commit,
CosmosSDK: cosmosSDK,
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.Fprintln(cmd.OutOrStdout(), string(bz))
return err
},
}
return jsonFlag(a.Viper, versionCmd)
}