From: Michael Tremer Date: Wed, 6 Jun 2012 15:44:59 +0000 (+0000) Subject: Improve yes/no decisions. X-Git-Tag: 004~48 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=39f552f5894d29396d8e0fd3128106980531ac02;p=network.git Improve yes/no decisions. If the user types something wrong, the question will be shown again until he answers yes or no. --- diff --git a/functions.cli b/functions.cli index c034fcb5..053a55f4 100644 --- a/functions.cli +++ b/functions.cli @@ -451,18 +451,22 @@ function cli_headline() { } function cli_yesno() { - local message="$@ [y/N] " + local message="$@ [y/n] " local yesno - echo - echo -ne "${message}" - read yesno + while true; do + printf "\n${message}" + read yesno - if listmatch ${yesno} y Y j J yes YES Yes; then - return ${EXIT_OK} - fi + # Check for "yes". + if listmatch ${yesno} y Y yes YES Yes; then + return ${EXIT_TRUE} - return ${EXIT_ERROR} + # Check for "no". + elif listmatch ${yesno} n N no NO No; then + return ${EXIT_FALSE} + fi + done } function cli_get_key() {