2018-02-14 09:57:48 -08:00
|
|
|
package version
|
2018-01-18 03:19:41 -08:00
|
|
|
|
2018-01-18 03:38:25 -08:00
|
|
|
import (
|
2019-01-29 14:25:43 -08:00
|
|
|
"encoding/json"
|
2020-07-07 10:20:09 -07:00
|
|
|
"strings"
|
2018-01-18 03:38:25 -08:00
|
|
|
|
|
|
|
"github.com/spf13/cobra"
|
2019-01-29 14:25:43 -08:00
|
|
|
"github.com/tendermint/tendermint/libs/cli"
|
2020-07-07 10:20:09 -07:00
|
|
|
yaml "gopkg.in/yaml.v2"
|
2019-01-29 14:25:43 -08:00
|
|
|
)
|
|
|
|
|
2019-05-18 16:06:08 -07:00
|
|
|
const flagLong = "long"
|
|
|
|
|
2021-05-11 06:08:23 -07:00
|
|
|
// NewVersionCommand returns a CLI command to interactively print the application binary version information.
|
2020-07-07 10:20:09 -07:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2020-10-27 08:46:57 -07:00
|
|
|
var (
|
|
|
|
bz []byte
|
|
|
|
err error
|
|
|
|
)
|
2020-07-07 10:20:09 -07:00
|
|
|
|
|
|
|
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
|
|
|
|
},
|
2020-02-28 10:14:01 -08:00
|
|
|
}
|
2019-05-31 06:14:35 -07:00
|
|
|
|
2020-07-07 10:20:09 -07:00
|
|
|
cmd.Flags().Bool(flagLong, false, "Print long version information")
|
|
|
|
cmd.Flags().StringP(cli.OutputFlag, "o", "text", "Output format (text|json)")
|
2020-02-28 10:14:01 -08:00
|
|
|
|
2020-07-07 10:20:09 -07:00
|
|
|
return cmd
|
2018-01-18 03:38:25 -08:00
|
|
|
}
|