forked from cosmos/cosmos-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommand.go
50 lines (38 loc) · 872 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
49
50
package version
import (
"encoding/json"
"github.com/spf13/cobra"
"github.com/spf13/viper"
yaml "gopkg.in/yaml.v2"
"github.com/tendermint/tendermint/libs/cli"
)
const flagLong = "long"
func init() {
Cmd.Flags().Bool(flagLong, false, "Print long version information")
}
// Cmd prints out the application's version information passed via build flags.
var Cmd = &cobra.Command{
Use: "version",
Short: "Print the app version",
RunE: runVersionCmd,
}
func runVersionCmd(cmd *cobra.Command, args []string) error {
verInfo := NewInfo()
if !viper.GetBool(flagLong) {
cmd.Println(verInfo.Version)
return nil
}
var bz []byte
var err error
switch viper.GetString(cli.OutputFlag) {
case "json":
bz, err = json.Marshal(verInfo)
default:
bz, err = yaml.Marshal(&verInfo)
}
if err != nil {
return err
}
cmd.Println(string(bz))
return nil
}