Commit 3877a286 authored by Matt Traudt's avatar Matt Traudt
Browse files

Modify query_yes_no to be easier to test cleanly

parent eae15aa2
...@@ -19,12 +19,15 @@ def query_yes_no(question, default='yes'): ...@@ -19,12 +19,15 @@ def query_yes_no(question, default='yes'):
prompt = ' [y/N] ' prompt = ' [y/N] '
else: else:
raise ValueError('invalid default answer: "%s"' % default) raise ValueError('invalid default answer: "%s"' % default)
prompt = question + prompt
first_loop = True
while True: while True:
print(question + prompt, end='') choice = input(prompt).lower()
choice = input().lower()
if default is not None and choice == '': if default is not None and choice == '':
return valid[default] return valid[default]
elif choice in valid: elif choice in valid:
return valid[choice] return valid[choice]
else: elif first_loop:
print('Please respond with "yes" or "no" (or "y" or "n").\n') prompt = 'Please respond with "yes" or "no" (or y or n).\n' +\
prompt
first_loop = False
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment