Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

R4R: Add indent to JSON of gaiacli key [add|show|list] #3841

Merged
merged 6 commits into from
Mar 13, 2019
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@

### Gaia CLI

* [\#3841](https://github.com/cosmos/cosmos-sdk/pull/3841) Add indent to JSON of `gaiacli keys [add|show|list]`
yangyanqing marked this conversation as resolved.
Show resolved Hide resolved

### Gaia

* #3808 `gaiad` and `gaiacli` integration tests use ./build/ binaries.
Expand Down
1 change: 1 addition & 0 deletions client/keys/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
5 changes: 4 additions & 1 deletion client/keys/list.go
Original file line number Diff line number Diff line change
@@ -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")
yangyanqing marked this conversation as resolved.
Show resolved Hide resolved
return cmd
}

func runListCmd(cmd *cobra.Command, args []string) error {
Expand Down
2 changes: 2 additions & 0 deletions client/keys/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
Expand Down
19 changes: 16 additions & 3 deletions client/keys/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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))
}
}
Expand Down