* Set proper default command output * Removed duplicated cmd.SetErr(cmd.ErrOrStderr()) and cmd.SetOut(cmd.OutOrStdout()) * Moved command initialization and added CHANGELOG * fix: groom all uses of cmd.Print* * Ran make format Co-authored-by: Michael FIG <mfig@agoric.com> Co-authored-by: Alessio Treglia <alessio@tendermint.com> Co-authored-by: Amaury <1293565+amaurym@users.noreply.github.com>
54 lines
1009 B
Go
54 lines
1009 B
Go
package version
|
|
|
|
import (
|
|
"encoding/json"
|
|
"strings"
|
|
|
|
"github.com/spf13/cobra"
|
|
"github.com/tendermint/tendermint/libs/cli"
|
|
yaml "gopkg.in/yaml.v2"
|
|
)
|
|
|
|
const flagLong = "long"
|
|
|
|
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
|
|
}
|