From 55c5d662290aea9f2c3abe911bd9920f4f9d7d9a Mon Sep 17 00:00:00 2001 From: erkin Date: Sun, 31 Jan 2021 07:26:22 +0300 Subject: vyos: T3274: Handle EOF in ask_yes_no() --- python/vyos/util.py | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/python/vyos/util.py b/python/vyos/util.py index 699f05892..ab5029c92 100644 --- a/python/vyos/util.py +++ b/python/vyos/util.py @@ -554,16 +554,19 @@ def ask_yes_no(question, default=False) -> bool: from sys import stdout default_msg = "[Y/n]" if default else "[y/N]" while True: - stdout.write("%s %s " % (question, default_msg)) - c = input().lower() - if c == '': - return default - elif c in ("y", "ye", "yes"): - return True - elif c in ("n", "no"): - return False - else: - stdout.write("Please respond with yes/y or no/n\n") + try: + stdout.write("%s %s " % (question, default_msg)) + c = input().lower() + if c == '': + return default + elif c in ("y", "ye", "yes"): + return True + elif c in ("n", "no"): + return False + else: + stdout.write("Please respond with yes/y or no/n\n") + except EOFError: + stdout.write("\nPlease respond with yes/y or no/n\n") def is_admin() -> bool: -- cgit v1.2.3