diff options
author | erkin <e.altunbas@vyos.io> | 2021-01-31 07:26:22 +0300 |
---|---|---|
committer | erkin <e.altunbas@vyos.io> | 2021-01-31 07:26:22 +0300 |
commit | 55c5d662290aea9f2c3abe911bd9920f4f9d7d9a (patch) | |
tree | 5b472cf0c1e324395082e99b4cf85f80f086cf06 /python/vyos | |
parent | 5e50f072478167a7e2027f39d4c8925c9c4fefde (diff) | |
download | vyos-1x-55c5d662290aea9f2c3abe911bd9920f4f9d7d9a.tar.gz vyos-1x-55c5d662290aea9f2c3abe911bd9920f4f9d7d9a.zip |
vyos: T3274: Handle EOF in ask_yes_no()
Diffstat (limited to 'python/vyos')
-rw-r--r-- | python/vyos/util.py | 23 |
1 files 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: |