diff --git a/cmd/oras/internal/option/confirmation.go b/cmd/oras/internal/option/confirmation.go index b18a5d9b1..87808297e 100644 --- a/cmd/oras/internal/option/confirmation.go +++ b/cmd/oras/internal/option/confirmation.go @@ -43,11 +43,14 @@ func (opts *Confirmation) AskForConfirmation(r io.Reader, prompt string) (bool, fmt.Print(prompt, " [y/N] ") + var response string scanner := bufio.NewScanner(r) - if ok := scanner.Scan(); !ok { - return false, scanner.Err() + if ok := scanner.Scan(); ok { + response = scanner.Text() + } + if err := scanner.Err(); err != nil { + return false, err } - response := scanner.Text() switch strings.ToLower(response) { case "y", "yes":