]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Improve the accessibility and robustness of prompt_bool.
authorPeter Powell <petpow@saberuk.com>
Tue, 29 Jan 2019 02:14:09 +0000 (02:14 +0000)
committerPeter Powell <petpow@saberuk.com>
Tue, 29 Jan 2019 21:18:18 +0000 (21:18 +0000)
- Use "yes" and "no" instead of "y" and "n".
- Validate the true and false responses properly.
- Keep prompting the user for a response until they give one which
  is valid.

make/console.pm

index 0d3c1b38d6f962fe96dda066346cb2ecdda5a1a3..132544caafe8b00d39b1ec3062eca25b11e72c41 100644 (file)
@@ -92,8 +92,12 @@ sub print_warning {
 
 sub prompt_bool($$$) {
        my ($interactive, $question, $default) = @_;
-       my $answer = prompt_string($interactive, $question, $default ? 'y' : 'n');
-       return $answer =~ /y/i;
+       while (1) {
+               my $answer = prompt_string($interactive, $question, $default ? 'yes' : 'no');
+               return 1 if $answer =~ /^y(?:es)?$/i;
+               return 0 if $answer =~ /^no?$/i;
+               print_warning "\"$answer\" is not \"yes\" or \"no\". Please try again.\n";
+       }
 }
 
 sub prompt_dir($$$;$) {