From c89a695d25a608c22425413400d11472b15b886e Mon Sep 17 00:00:00 2001 From: Billy Zha Date: Fri, 25 Nov 2022 10:12:35 +0800 Subject: [PATCH 1/2] fix: add log when failed to scan confirmation Signed-off-by: Billy Zha --- cmd/oras/internal/option/confirmation.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/cmd/oras/internal/option/confirmation.go b/cmd/oras/internal/option/confirmation.go index b18a5d9b1..937b18130 100644 --- a/cmd/oras/internal/option/confirmation.go +++ b/cmd/oras/internal/option/confirmation.go @@ -45,7 +45,12 @@ func (opts *Confirmation) AskForConfirmation(r io.Reader, prompt string) (bool, scanner := bufio.NewScanner(r) if ok := scanner.Scan(); !ok { - return false, scanner.Err() + err := scanner.Err() + if err == nil { + // EOF + fmt.Println("Operation cancelled.") + } + return false, err } response := scanner.Text() From b94e5fede2d825514dff57311d3e19bccd0ccf6c Mon Sep 17 00:00:00 2001 From: Billy Zha Date: Fri, 25 Nov 2022 10:47:27 +0800 Subject: [PATCH 2/2] fix bug Signed-off-by: Billy Zha --- cmd/oras/internal/option/confirmation.go | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/cmd/oras/internal/option/confirmation.go b/cmd/oras/internal/option/confirmation.go index 937b18130..87808297e 100644 --- a/cmd/oras/internal/option/confirmation.go +++ b/cmd/oras/internal/option/confirmation.go @@ -43,16 +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 { - err := scanner.Err() - if err == nil { - // EOF - fmt.Println("Operation cancelled.") - } + 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":