forked from cosmos/cosmos-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommand.go
54 lines (42 loc) · 1.09 KB
/
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
51
52
53
54
package version
import (
"encoding/json"
"strings"
"github.com/spf13/cobra"
"github.com/tendermint/tendermint/libs/cli"
"sigs.k8s.io/yaml"
)
const flagLong = "long"
// NewVersionCommand returns a CLI command to interactively print the application binary version information.
func NewVersionCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "version",
Short: "Print the application binary version information",
RunE: func(cmd *cobra.Command, _ []string) error {
verInfo := NewInfo()
if long, _ := cmd.Flags().GetBool(flagLong); !long {
cmd.Println(verInfo.Version)
return nil
}
var (
bz []byte
err error
)
output, _ := cmd.Flags().GetString(cli.OutputFlag)
switch strings.ToLower(output) {
case "json":
bz, err = json.Marshal(verInfo)
default:
bz, err = yaml.Marshal(&verInfo)
}
if err != nil {
return err
}
cmd.Println(string(bz))
return nil
},
}
cmd.Flags().Bool(flagLong, false, "Print long version information")
cmd.Flags().StringP(cli.OutputFlag, "o", "text", "Output format (text|json)")
return cmd
}