From 810ba10866fe2a5bced85258fc79fd9f8c681e07 Mon Sep 17 00:00:00 2001 From: yihuang Date: Wed, 19 May 2021 16:44:15 +0800 Subject: [PATCH] fix client config don't take effect (#9211) * fix client keyring config * fix output flag of keys commads Co-authored-by: Robert Zaremba Co-authored-by: Amaury <1293565+amaurym@users.noreply.github.com> --- client/config/config.go | 3 ++- client/keys/add.go | 15 +++++++-------- client/keys/show.go | 6 ++++-- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/client/config/config.go b/client/config/config.go index 391a0bf4a620..6297cf2c26b1 100644 --- a/client/config/config.go +++ b/client/config/config.go @@ -73,7 +73,8 @@ func ReadFromClientConfig(ctx client.Context) (client.Context, error) { } // we need to update KeyringDir field on Client Context first cause it is used in NewKeyringFromBackend ctx = ctx.WithOutputFormat(conf.Output). - WithChainID(conf.ChainID) + WithChainID(conf.ChainID). + WithKeyringDir(ctx.HomeDir) keyring, err := client.NewKeyringFromBackend(ctx, conf.KeyringBackend) if err != nil { diff --git a/client/keys/add.go b/client/keys/add.go index 25cfa46c1456..19a927f73953 100644 --- a/client/keys/add.go +++ b/client/keys/add.go @@ -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" @@ -109,6 +108,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) @@ -201,7 +201,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 @@ -275,15 +275,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 { @@ -310,7 +309,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 diff --git a/client/keys/show.go b/client/keys/show.go index 8c19f8797679..64ede012582f 100644 --- a/client/keys/show.go +++ b/client/keys/show.go @@ -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: @@ -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 {