client/keys: make add command's output parseable (#6603)
client/input/input.go: GetConfirmation() should communicate with the user via the io.Writer instance passed in as argument. client/keys/add.go: replace cmd.PrintErrln() calls with fmt.Fprintln(cmd.ErrOrStderr(), ...) because of cobra's PrintErr* functions broken behaviour. For more information please see https://github.com/spf13/cobra/pull/894 Closes: #6601 Thanks: @noandrea for pointing this out.
This commit is contained in:
parent
4380d03068
commit
b832e103b1
|
@ -41,7 +41,7 @@ func GetPassword(prompt string, buf *bufio.Reader) (pass string, err error) {
|
|||
// If the input is not recognized, it returns false and a nil error.
|
||||
func GetConfirmation(prompt string, r *bufio.Reader, w io.Writer) (bool, error) {
|
||||
if inputIsTty() {
|
||||
fmt.Printf("%s [y/N]: ", prompt)
|
||||
fmt.Fprintf(w, "%s [y/N]: ", prompt)
|
||||
}
|
||||
|
||||
response, err := readLineFromBuf(r)
|
||||
|
|
|
@ -80,6 +80,9 @@ the flag --nosort is set.
|
|||
cmd.Flags().Uint32(flagIndex, 0, "Address index number for HD derivation")
|
||||
cmd.Flags().String(flagKeyAlgo, string(hd.Secp256k1Type), "Key signing algorithm to generate keys for")
|
||||
|
||||
cmd.SetOut(cmd.OutOrStdout())
|
||||
cmd.SetErr(cmd.ErrOrStderr())
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
|
@ -115,7 +118,6 @@ func RunAddCmd(cmd *cobra.Command, args []string, kb keyring.Keyring, inBuf *buf
|
|||
var err error
|
||||
|
||||
name := args[0]
|
||||
|
||||
interactive := viper.GetBool(flagInteractive)
|
||||
showMnemonic := !viper.GetBool(flagNoBackup)
|
||||
|
||||
|
@ -295,10 +297,11 @@ func printCreate(cmd *cobra.Command, info keyring.Info, showMnemonic bool, mnemo
|
|||
|
||||
// print mnemonic unless requested not to.
|
||||
if showMnemonic {
|
||||
cmd.PrintErrln("\n**Important** write this mnemonic phrase in a safe place.")
|
||||
cmd.PrintErrln("It is the only way to recover your account if you ever forget your password.")
|
||||
cmd.PrintErrln("")
|
||||
cmd.PrintErrln(mnemonic)
|
||||
fmt.Fprintln(cmd.ErrOrStderr(), "\n**Important** write this mnemonic phrase in a safe place.")
|
||||
fmt.Fprintln(cmd.ErrOrStderr(), "\n**Important** write this mnemonic phrase in a safe place.")
|
||||
fmt.Fprintln(cmd.ErrOrStderr(), "It is the only way to recover your account if you ever forget your password.")
|
||||
fmt.Fprintln(cmd.ErrOrStderr(), "")
|
||||
fmt.Fprintln(cmd.ErrOrStderr(), mnemonic)
|
||||
}
|
||||
case OutputFormatJSON:
|
||||
out, err := keyring.Bech32KeyOutput(info)
|
||||
|
@ -315,7 +318,7 @@ func printCreate(cmd *cobra.Command, info keyring.Info, showMnemonic bool, mnemo
|
|||
return err
|
||||
}
|
||||
|
||||
cmd.PrintErrln(string(jsonString))
|
||||
cmd.Println(string(jsonString))
|
||||
|
||||
default:
|
||||
return fmt.Errorf("invalid output format %s", output)
|
||||
|
|
Loading…
Reference in New Issue