Skip to content

Commit

Permalink
Merge PR #3841: Add indent to JSON of gaiacli key [add|show|list]
Browse files Browse the repository at this point in the history
* Add indent to JSON of `gaiacli key list`

* Add `-o json --indent` to `keys [add|show|list]`

* Add change log.

* Move entry from CHANGELOG.md to PENDING.md

* Update PENDING.md

Add indent to JSON of `gaiacli key [add|show|list]`

Co-Authored-By: yangyanqing <yangyanqing.cn@gmail.com>
  • Loading branch information
yangyanqing authored and jackzampolin committed Mar 13, 2019
1 parent 5b62109 commit 54ac1d2
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 4 deletions.
1 change: 1 addition & 0 deletions PENDING.md
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions client/keys/add.go
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
@@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions client/keys/show.go
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
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

0 comments on commit 54ac1d2

Please sign in to comment.