Merge PR #3426: Various changes to version cmd, revert those which previously broke ABI

* version prints out short info by default

Handle -o json, add --long flag to print full version info.

* Add distclean target to Makefile

* Update PENDING.md

* Add missing targets in .PHONY
This commit is contained in:
Alessio Treglia 2019-01-29 14:25:43 -08:00 committed by Christopher Goes
parent 172a4510c7
commit 0ed6de0cbd
6 changed files with 63 additions and 17 deletions

View File

@ -124,6 +124,9 @@ draw_deps: tools
clean: clean:
rm -f devtools-stamp vendor-deps snapcraft.yaml rm -f devtools-stamp vendor-deps snapcraft.yaml
distclean: clean
rm -rf vendor/
######################################## ########################################
### Documentation ### Documentation
@ -250,7 +253,7 @@ build-snap-edge: snapcraft.yaml
# To avoid unintended conflicts with file names, always add to .PHONY # To avoid unintended conflicts with file names, always add to .PHONY
# unless there is a reason not to. # unless there is a reason not to.
# https://www.gnu.org/software/make/manual/html_node/Phony-Targets.html # https://www.gnu.org/software/make/manual/html_node/Phony-Targets.html
.PHONY: build install install_debug dist \ .PHONY: build install install_debug dist clean distclean \
check_tools check_dev_tools get_vendor_deps draw_deps test test_cli test_unit \ check_tools check_dev_tools get_vendor_deps draw_deps test test_cli test_unit \
test_cover test_lint benchmark devdoc_init devdoc devdoc_save devdoc_update \ test_cover test_lint benchmark devdoc_init devdoc devdoc_save devdoc_update \
build-linux build-docker-gaiadnode localnet-start localnet-stop \ build-linux build-docker-gaiadnode localnet-start localnet-stop \

View File

@ -8,6 +8,7 @@ BREAKING CHANGES
* Gaia CLI (`gaiacli`) * Gaia CLI (`gaiacli`)
- [#3399](https://github.com/cosmos/cosmos-sdk/pull/3399) Add `gaiad validate-genesis` command to facilitate checking of genesis files - [#3399](https://github.com/cosmos/cosmos-sdk/pull/3399) Add `gaiad validate-genesis` command to facilitate checking of genesis files
- [\#1894](https://github.com/cosmos/cosmos-sdk/issues/1894) `version` prints out short info by default. Add `--long` flag. Proper handling of `--format` flag introduced.
* Gaia * Gaia

View File

@ -396,7 +396,7 @@ func handleQueryApp(app *BaseApp, path []string, req abci.RequestQuery) (res abc
return abci.ResponseQuery{ return abci.ResponseQuery{
Code: uint32(sdk.CodeOK), Code: uint32(sdk.CodeOK),
Codespace: string(sdk.CodespaceRoot), Codespace: string(sdk.CodespaceRoot),
Value: []byte(version.GetVersion()), Value: []byte(version.Version),
} }
default: default:
result = sdk.ErrUnknownRequest(fmt.Sprintf("Unknown query: %s", path)).Result() result = sdk.ErrUnknownRequest(fmt.Sprintf("Unknown query: %s", path)).Result()

View File

@ -26,7 +26,7 @@ func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router) {
// cli version REST handler endpoint // cli version REST handler endpoint
func CLIVersionRequestHandler(w http.ResponseWriter, r *http.Request) { func CLIVersionRequestHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json") w.Header().Set("Content-Type", "application/json")
w.Write([]byte(fmt.Sprintf("{\"version\": \"%s\"}", version.GetVersion()))) w.Write([]byte(fmt.Sprintf("{\"version\": \"%s\"}", version.Version)))
} }
// connected node version REST handler endpoint // connected node version REST handler endpoint

View File

@ -1,31 +1,48 @@
package version package version
import ( import (
"encoding/json"
"fmt" "fmt"
"runtime"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/tendermint/tendermint/libs/cli"
)
const (
flagLong = "long"
) )
var ( var (
// VersionCmd prints out the current sdk version // VersionCmd prints out the current sdk version
VersionCmd = &cobra.Command{ VersionCmd = &cobra.Command{
Use: "version", Use: "version",
Short: "Print the app version", Short: "Print the app version",
Run: printVersion, 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
},
} }
) )
// return version of CLI/node and commit hash func init() {
func GetVersion() string { VersionCmd.Flags().Bool(flagLong, false, "Print long version information")
return Version
}
// CMD
func printVersion(cmd *cobra.Command, args []string) {
fmt.Println("cosmos-sdk:", GetVersion())
fmt.Println("git commit:", Commit)
fmt.Println("vendor hash:", VendorDirHash)
fmt.Printf("go version %s %s/%s\n",
runtime.Version(), runtime.GOOS, runtime.GOARCH)
} }

View File

@ -1,9 +1,34 @@
//nolint //nolint
package version package version
import (
"fmt"
"runtime"
)
// Variables set by build flags // Variables set by build flags
var ( var (
Commit = "" Commit = ""
Version = "" Version = ""
VendorDirHash = "" VendorDirHash = ""
) )
type versionInfo struct {
CosmosSDK string `json:"cosmos_sdk"`
GitCommit string `json:"commit"`
VendorDirHash string `json:"vendor_hash"`
GoVersion string `json:"go"`
}
func (v versionInfo) String() string {
return fmt.Sprintf(`cosmos-sdk: %s
git commit: %s
vendor hash: %s
%s`, v.CosmosSDK, v.GitCommit, v.VendorDirHash, v.GoVersion)
}
func newVersionInfo() versionInfo {
return versionInfo{
Version, Commit, VendorDirHash, fmt.Sprintf("go version %s %s/%s\n",
runtime.Version(), runtime.GOOS, runtime.GOARCH)}
}