From 61bb732495f8a74cf1bc4ffa8ddc5a69e66862a1 Mon Sep 17 00:00:00 2001 From: Frank Yang Date: Sat, 9 Mar 2019 17:30:38 +0800 Subject: [PATCH 1/5] Add indent to JSON of `gaiacli key list` --- client/keys/list.go | 5 ++++- client/keys/utils.go | 12 ++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/client/keys/list.go b/client/keys/list.go index db4cf0fe2f71..19873aabb77b 100644 --- a/client/keys/list.go +++ b/client/keys/list.go @@ -1,17 +1,20 @@ package keys import ( + "github.com/cosmos/cosmos-sdk/client" "github.com/spf13/cobra" ) func listKeysCmd() *cobra.Command { - return &cobra.Command{ + cmd := &cobra.Command{ Use: "list", Short: "List all keys", Long: `Return a list of all public keys stored by this key manager along with their associated name and address.`, RunE: runListCmd, } + cmd.Flags().Bool(client.FlagIndentResponse, false, "Add indent to JSON response") + return cmd } func runListCmd(cmd *cobra.Command, args []string) error { diff --git a/client/keys/utils.go b/client/keys/utils.go index 3dfcd735beaf..31885204b858 100644 --- a/client/keys/utils.go +++ b/client/keys/utils.go @@ -142,11 +142,19 @@ func printInfos(infos []keys.Info) { } case OutputFormatJSON: - out, err := MarshalJSON(kos) + var out []byte + var err error + + switch viper.Get(client.FlagIndentResponse) { + case true: + out, err = cdc.MarshalJSONIndent(kos, "", " ") + case false: + out, err = cdc.MarshalJSON(kos) + } + if err != nil { panic(err) } - fmt.Println(string(out)) } } From 94b398b0d4ccddc82ff426e6afe8fdbd5a2d46f5 Mon Sep 17 00:00:00 2001 From: Frank Yang Date: Mon, 11 Mar 2019 11:50:51 +0800 Subject: [PATCH 2/5] Add `-o json --indent` to `keys [add|show|list]` --- client/keys/add.go | 1 + client/keys/show.go | 2 ++ client/keys/utils.go | 13 +++++++++---- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/client/keys/add.go b/client/keys/add.go index c11316d1d12d..be4e5d2d8f35 100644 --- a/client/keys/add.go +++ b/client/keys/add.go @@ -74,6 +74,7 @@ the flag --nosort is set. cmd.Flags().Bool(flagDryRun, false, "Perform action, but don't add key to local keystore") cmd.Flags().Uint32(flagAccount, 0, "Account number for HD derivation") cmd.Flags().Uint32(flagIndex, 0, "Address index number for HD derivation") + cmd.Flags().Bool(client.FlagIndentResponse, false, "Add indent to JSON response") return cmd } diff --git a/client/keys/show.go b/client/keys/show.go index e1d253cd3727..eaa800e11fbe 100644 --- a/client/keys/show.go +++ b/client/keys/show.go @@ -3,6 +3,7 @@ package keys import ( "errors" "fmt" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/crypto" "github.com/cosmos/cosmos-sdk/crypto/keys" @@ -49,6 +50,7 @@ consisting of all the keys provided by name and multisig threshold.`, cmd.Flags().BoolP(FlagDevice, "d", false, "Output the address in the device") cmd.Flags().Uint(flagMultiSigThreshold, 1, "K out of N required signatures") cmd.Flags().BoolP(flagShowMultiSig, "m", false, "Output multisig pubkey constituents, threshold, and weights") + cmd.Flags().Bool(client.FlagIndentResponse, false, "Add indent to JSON response") return cmd } diff --git a/client/keys/utils.go b/client/keys/utils.go index 31885204b858..c86161038435 100644 --- a/client/keys/utils.go +++ b/client/keys/utils.go @@ -119,7 +119,13 @@ func printKeyInfo(keyInfo keys.Info, bechKeyOut bechKeyOutFn) { printKeyOutput(ko) case OutputFormatJSON: - out, err := MarshalJSON(ko) + var out []byte + var err error + if viper.GetBool(client.FlagIndentResponse) { + out, err = cdc.MarshalJSONIndent(ko, "", " ") + } else { + out, err = cdc.MarshalJSON(ko) + } if err != nil { panic(err) } @@ -145,10 +151,9 @@ func printInfos(infos []keys.Info) { var out []byte var err error - switch viper.Get(client.FlagIndentResponse) { - case true: + if viper.GetBool(client.FlagIndentResponse) { out, err = cdc.MarshalJSONIndent(kos, "", " ") - case false: + } else { out, err = cdc.MarshalJSON(kos) } From b1e123832253f2818db193173b8f747f0591492e Mon Sep 17 00:00:00 2001 From: Frank Yang Date: Mon, 11 Mar 2019 12:07:21 +0800 Subject: [PATCH 3/5] Add change log. --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a3eeb79a9285..9cc07be09d8f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -65,6 +65,7 @@ IMPROVEMENTS * [\#3730](https://github.com/cosmos/cosmos-sdk/issues/3730) Improve workflow for `gaiad gentx` with offline public keys, by outputting stdtx file that needs to be signed. * [\#3761](https://github.com/cosmos/cosmos-sdk/issues/3761) Querying account related information using custom querier in auth module + * [\#3841](https://github.com/cosmos/cosmos-sdk/pull/3841) Add indent to JSON of `gaiacli key [add|show|list]` * SDK * [\#3753](https://github.com/cosmos/cosmos-sdk/issues/3753) Remove no-longer-used governance penalty parameter From 23e68d949e6ad2c21a71e72ce0d37d6fb98df239 Mon Sep 17 00:00:00 2001 From: Frank Yang Date: Tue, 12 Mar 2019 07:21:59 +0800 Subject: [PATCH 4/5] Move entry from CHANGELOG.md to PENDING.md --- CHANGELOG.md | 1 - PENDING.md | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9cc07be09d8f..a3eeb79a9285 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -65,7 +65,6 @@ IMPROVEMENTS * [\#3730](https://github.com/cosmos/cosmos-sdk/issues/3730) Improve workflow for `gaiad gentx` with offline public keys, by outputting stdtx file that needs to be signed. * [\#3761](https://github.com/cosmos/cosmos-sdk/issues/3761) Querying account related information using custom querier in auth module - * [\#3841](https://github.com/cosmos/cosmos-sdk/pull/3841) Add indent to JSON of `gaiacli key [add|show|list]` * SDK * [\#3753](https://github.com/cosmos/cosmos-sdk/issues/3753) Remove no-longer-used governance penalty parameter diff --git a/PENDING.md b/PENDING.md index 007108cf75ac..ee027421f209 100644 --- a/PENDING.md +++ b/PENDING.md @@ -38,6 +38,7 @@ ### Gaia REST API ### Gaia CLI +* [\#3841](https://github.com/cosmos/cosmos-sdk/pull/3841) Add indent to JSON of `gaiacli keys [add|show|list]` ### Gaia From 0191b933bc024718afc91948fb2bf47f1e82d997 Mon Sep 17 00:00:00 2001 From: Alexander Bezobchuk Date: Thu, 14 Mar 2019 00:25:47 +0800 Subject: [PATCH 5/5] Update PENDING.md Add indent to JSON of `gaiacli key [add|show|list]` Co-Authored-By: yangyanqing --- PENDING.md | 1 + 1 file changed, 1 insertion(+) diff --git a/PENDING.md b/PENDING.md index ee027421f209..fa4daa2e3ed2 100644 --- a/PENDING.md +++ b/PENDING.md @@ -38,6 +38,7 @@ ### Gaia REST API ### Gaia CLI + * [\#3841](https://github.com/cosmos/cosmos-sdk/pull/3841) Add indent to JSON of `gaiacli keys [add|show|list]` ### Gaia