Skip to content

Commit

Permalink
switch GetConfirmation()'s default to no
Browse files Browse the repository at this point in the history
GetConfirmation() returns true if and only if the user's
input is confirmative.

The function is used in places where fat-fingering may cause
financial loss, e.g. gaiacli tx send command. Thus it seems
wiser to provide a conservative default in order to protect
users from accidental mistyping.

Closes: #4564
  • Loading branch information
alessio committed Jun 18, 2019
1 parent 36142ab commit 3ebd439
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .pending/improvements/sdk/4564-Allow-empty-ans
Original file line number Diff line number Diff line change
@@ -1 +1 @@
#4564 Allow empty answer to evaluate as 'Y' on tx submission prompt.
#4564 client/input.GetConfirmation()'s default is changed to No.
10 changes: 5 additions & 5 deletions client/input/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
}
}

Expand Down

0 comments on commit 3ebd439

Please sign in to comment.