diff options
author | Nicolas Chauvat <nicolas.chauvat@logilab.fr> | 2009-08-01 00:35:26 +0200 |
---|---|---|
committer | Nicolas Chauvat <nicolas.chauvat@logilab.fr> | 2009-08-01 00:35:26 +0200 |
commit | cbe6d7c15ecdde3e0468fee298ccdc5583edc1df (patch) | |
tree | b88dc6e2feedae90cc57167b3a304b3f3c96e1f6 /shellutils.py | |
parent | c9996a3223803ed28c2484eac78cca243be362d2 (diff) | |
download | logilab-common-cbe6d7c15ecdde3e0468fee298ccdc5583edc1df.tar.gz |
F [shellutils] ask again if input data is not an option
Diffstat (limited to 'shellutils.py')
-rw-r--r-- | shellutils.py | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/shellutils.py b/shellutils.py index 93f8f8c..23a1723 100644 --- a/shellutils.py +++ b/shellutils.py @@ -307,15 +307,17 @@ class RawInput(object): tries = 3 while tries > 0: answer = self._input(prompt).strip().lower() - if answer: - possible = [option for option, label in choices - if option.lower().startswith(answer)] - if len(possible) == 1: - return possible[0] - else: + if not answer: return default - msg = ('%s is an ambiguous answer, do you mean %s ?' % ( - answer, ' or '.join(possible))) + possible = [option for option, label in choices + if option.lower().startswith(answer)] + if len(possible) == 1: + return possible[0] + elif len(possible) == 0: + msg = '%s is not an option.' % answer + else: + msg = ('%s is an ambiguous answer, do you mean %s ?' % ( + answer, ' or '.join(possible))) if self._print: self._print(msg) else: |