summaryrefslogtreecommitdiff
path: root/python/vyos/util.py
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2021-01-31 09:34:47 +0100
committerGitHub <noreply@github.com>2021-01-31 09:34:47 +0100
commita644206780699ab2878d4b127ebb00d266c3b272 (patch)
tree96b6423d2b66b8537df52ffd74d07817e3bca300 /python/vyos/util.py
parentcd19bd15ca2adf4a36793a6c88ffd9f35fae85a0 (diff)
parent55c5d662290aea9f2c3abe911bd9920f4f9d7d9a (diff)
downloadvyos-1x-a644206780699ab2878d4b127ebb00d266c3b272.tar.gz
vyos-1x-a644206780699ab2878d4b127ebb00d266c3b272.zip
Merge pull request #712 from erkin/current
vyos: T3274: Handle EOF in ask_yes_no()
Diffstat (limited to 'python/vyos/util.py')
-rw-r--r--python/vyos/util.py23
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: