Skip to content

Commit

Permalink
fix output flag of keys commads
Browse files Browse the repository at this point in the history
  • Loading branch information
yihuang committed Apr 27, 2021
1 parent 02bf215 commit 3a5a5f3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
15 changes: 7 additions & 8 deletions client/keys/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (

bip39 "github.com/cosmos/go-bip39"
"github.com/spf13/cobra"
"github.com/tendermint/tendermint/libs/cli"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
Expand Down Expand Up @@ -110,6 +109,7 @@ func RunAddCmd(ctx client.Context, cmd *cobra.Command, args []string, inBuf *buf
noBackup, _ := cmd.Flags().GetBool(flagNoBackup)
showMnemonic := !noBackup
kb := ctx.Keyring
outputFormat := ctx.OutputFormat

keyringAlgos, _ := kb.SupportedAlgorithms()
algoStr, _ := cmd.Flags().GetString(flags.FlagKeyAlgorithm)
Expand Down Expand Up @@ -202,7 +202,7 @@ func RunAddCmd(ctx client.Context, cmd *cobra.Command, args []string, inBuf *buf
return err
}

return printCreate(cmd, info, false, "")
return printCreate(cmd, info, false, "", outputFormat)
}

// Get bip39 mnemonic
Expand Down Expand Up @@ -276,15 +276,14 @@ func RunAddCmd(ctx client.Context, cmd *cobra.Command, args []string, inBuf *buf
mnemonic = ""
}

return printCreate(cmd, info, showMnemonic, mnemonic)
return printCreate(cmd, info, showMnemonic, mnemonic, outputFormat)
}

func printCreate(cmd *cobra.Command, info keyring.Info, showMnemonic bool, mnemonic string) error {
output, _ := cmd.Flags().GetString(cli.OutputFlag)
switch output {
func printCreate(cmd *cobra.Command, info keyring.Info, showMnemonic bool, mnemonic string, outputFormat string) error {
switch outputFormat {
case OutputFormatText:
cmd.PrintErrln()
printKeyInfo(cmd.OutOrStdout(), info, keyring.MkAccKeyOutput, output)
printKeyInfo(cmd.OutOrStdout(), info, keyring.MkAccKeyOutput, outputFormat)

// print mnemonic unless requested not to.
if showMnemonic {
Expand All @@ -311,7 +310,7 @@ func printCreate(cmd *cobra.Command, info keyring.Info, showMnemonic bool, mnemo
cmd.Println(string(jsonString))

default:
return fmt.Errorf("invalid output format %s", output)
return fmt.Errorf("invalid output format %s", outputFormat)
}

return nil
Expand Down
6 changes: 4 additions & 2 deletions client/keys/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,9 @@ func runShowCmd(cmd *cobra.Command, args []string) (err error) {
return err
}

output, _ := cmd.Flags().GetString(cli.OutputFlag)
if isOutputSet {
clientCtx.OutputFormat, _ = cmd.Flags().GetString(cli.OutputFlag)
}

switch {
case isShowAddr, isShowPubKey:
Expand All @@ -126,7 +128,7 @@ func runShowCmd(cmd *cobra.Command, args []string) (err error) {
}
fmt.Fprintln(cmd.OutOrStdout(), out)
default:
printKeyInfo(cmd.OutOrStdout(), info, bechKeyOut, output)
printKeyInfo(cmd.OutOrStdout(), info, bechKeyOut, clientCtx.OutputFormat)
}

if isShowDevice {
Expand Down

0 comments on commit 3a5a5f3

Please sign in to comment.