raco pkg: handle EOF reply to interactive question

Closes #3523
This commit is contained in:
Matthew Flatt 2020-11-27 10:50:16 -07:00
parent 1828ff5697
commit 7375316478

View File

@ -49,24 +49,30 @@
(if default-yes? "Y" "y")
(if default-yes? "n" "N"))
(flush-output)
(match (string-trim (read-line (current-input-port) 'any))
[(or "y" "Y")
'yes]
[(or "n" "N")
'no]
[(or "a" "A")
'always-yes]
[(or "c" "C")
(define reply (read-line (current-input-port) 'any))
(cond
[(eof-object? reply)
(eprintf "\nTreating end-of-file input as \"cancel\".\n")
'cancel]
[""
(if default-yes? 'yes 'no)]
[x
(eprintf "Invalid answer: ~a\n" x)
(eprintf " Answer ~a`y' or `Y' for \"yes\", ~a`n' or `N' for \"no\", or\n"
(if default-yes? "nothing or " "")
(if default-yes? "" "nothing or "))
(eprintf " `a' or `A' for \"yes for all\", or `c' or `C' for \"cancel\".\n")
(loop)])))
[else
(match (string-trim reply)
[(or "y" "Y")
'yes]
[(or "n" "N")
'no]
[(or "a" "A")
'always-yes]
[(or "c" "C")
'cancel]
[""
(if default-yes? 'yes 'no)]
[x
(eprintf "Invalid answer: ~a\n" x)
(eprintf " Answer ~a`y' or `Y' for \"yes\", ~a`n' or `N' for \"no\", or\n"
(if default-yes? "nothing or " "")
(if default-yes? "" "nothing or "))
(eprintf " `a' or `A' for \"yes for all\", or `c' or `C' for \"cancel\".\n")
(loop)])])))
(define (dry-run-explain dry-run?)