diff --git a/.pending/improvements/sdk/4564-Allow-empty-ans b/.pending/improvements/sdk/4564-Allow-empty-ans index 9d134996cff9..22a4d02bba90 100644 --- a/.pending/improvements/sdk/4564-Allow-empty-ans +++ b/.pending/improvements/sdk/4564-Allow-empty-ans @@ -1 +1 @@ -#4564 Allow empty answer to evaluate as 'Y' on tx submission prompt. +#4564 client/input.GetConfirmation()'s default is changed to No. diff --git a/client/input/input.go b/client/input/input.go index 4549493b26ec..2ff691432c1b 100644 --- a/client/input/input.go +++ b/client/input/input.go @@ -85,11 +85,11 @@ func GetCheckPassword(prompt, prompt2 string, buf *bufio.Reader) (string, error) // GetConfirmation will request user give the confirmation from stdin. // "y", "Y", "yes", "YES", and "Yes" all count as confirmations. -// If the input is not recognized, it will ask again. +// If the input is not recognized, it returns false and a nil error. func GetConfirmation(prompt string, buf *bufio.Reader) (bool, error) { for { if inputIsTty() { - fmt.Print(fmt.Sprintf("%s [Y/n]: ", prompt)) + fmt.Print(fmt.Sprintf("%s [y/N]: ", prompt)) } response, err := readLineFromBuf(buf) @@ -98,11 +98,11 @@ func GetConfirmation(prompt string, buf *bufio.Reader) (bool, error) { } response = strings.ToLower(strings.TrimSpace(response)) - if response == "y" || response == "yes" || response == "" { + if response[0] == 'y' { return true, nil - } else if response == "n" || response == "no" { - return false, nil } + + return false, nil } } diff --git a/client/keys/add.go b/client/keys/add.go index 948b4585b309..c0752c406944 100644 --- a/client/keys/add.go +++ b/client/keys/add.go @@ -110,10 +110,13 @@ func runAddCmd(_ *cobra.Command, args []string) error { _, err = kb.Get(name) if err == nil { // account exists, ask for user confirmation - if response, err2 := input.GetConfirmation( - fmt.Sprintf("override the existing name %s", name), buf); err2 != nil || !response { + response, err2 := input.GetConfirmation(fmt.Sprintf("override the existing name %s", name), buf) + if err2 != nil { return err2 } + if !response { + return errors.New("aborted") + } } multisigKeys := viper.GetStringSlice(flagMultisig)