]> git.ipfire.org Git - people/stevee/network.git/commitdiff
Improve yes/no decisions.
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 6 Jun 2012 15:44:59 +0000 (15:44 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 6 Jun 2012 15:44:59 +0000 (15:44 +0000)
If the user types something wrong, the question will
be shown again until he answers yes or no.

functions.cli

index c034fcb584d39bf86aa0163eb7ca3c6bb0e64703..053a55f4b018261c86cea7528dc2edaa27e2bfc0 100644 (file)
@@ -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() {