forked from cosmos/cosmos-sdk
/
command.go
48 lines (38 loc) · 808 Bytes
/
command.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
package version
import (
"encoding/json"
"fmt"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/tendermint/tendermint/libs/cli"
)
const (
flagLong = "long"
)
var (
// VersionCmd prints out the current sdk version
VersionCmd = &cobra.Command{
Use: "version",
Short: "Print the app version",
RunE: func(_ *cobra.Command, _ []string) error {
verInfo := newVersionInfo()
if !viper.GetBool(flagLong) {
fmt.Println(verInfo.CosmosSDK)
return nil
}
if viper.GetString(cli.OutputFlag) != "json" {
fmt.Print(verInfo)
return nil
}
bz, err := json.Marshal(verInfo)
if err != nil {
return err
}
fmt.Println(string(bz))
return nil
},
}
)
func init() {
VersionCmd.Flags().Bool(flagLong, false, "Print long version information")
}