diff --git a/PENDING.md b/PENDING.md index 3708b7bae..b6021332f 100644 --- a/PENDING.md +++ b/PENDING.md @@ -39,6 +39,7 @@ ### Gaia CLI +* [\#3841](https://github.com/cosmos/cosmos-sdk/pull/3841) Add indent to JSON of `gaiacli keys [add|show|list]` * [\#3859](https://github.com/cosmos/cosmos-sdk/pull/3859) Add newline to echo of `gaiacli keys ...` ### Gaia diff --git a/client/keys/add.go b/client/keys/add.go index bf5901e65..7ab5ecdb8 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/list.go b/client/keys/list.go index db4cf0fe2..19873aabb 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/show.go b/client/keys/show.go index e1d253cd3..eaa800e11 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 3dfcd735b..c86161038 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) } @@ -142,11 +148,18 @@ func printInfos(infos []keys.Info) { } case OutputFormatJSON: - out, err := MarshalJSON(kos) + var out []byte + var err error + + if viper.GetBool(client.FlagIndentResponse) { + out, err = cdc.MarshalJSONIndent(kos, "", " ") + } else { + out, err = cdc.MarshalJSON(kos) + } + if err != nil { panic(err) } - fmt.Println(string(out)) } }