diff options
author | sarthurdev <965089+sarthurdev@users.noreply.github.com> | 2021-06-17 18:08:58 +0200 |
---|---|---|
committer | sarthurdev <965089+sarthurdev@users.noreply.github.com> | 2021-06-29 15:13:34 +0200 |
commit | 6f66e71e4622c54058b8689d4be730905d69fe22 (patch) | |
tree | fe0b2b4d097b88b7f62c27486ce25351119edd0f /python/vyos/util.py | |
parent | 09efa0550dd169e30a851513781b611dd84e9c79 (diff) | |
download | vyos-1x-6f66e71e4622c54058b8689d4be730905d69fe22.tar.gz vyos-1x-6f66e71e4622c54058b8689d4be730905d69fe22.zip |
pki: T3642: New PKI config and management
Diffstat (limited to 'python/vyos/util.py')
-rw-r--r-- | python/vyos/util.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/python/vyos/util.py b/python/vyos/util.py index c318d58de..c3bf481ea 100644 --- a/python/vyos/util.py +++ b/python/vyos/util.py @@ -566,6 +566,25 @@ def wait_for_commit_lock(): while commit_in_progress(): sleep(1) +def ask_input(question, default='', numeric_only=False, valid_responses=[]): + question_out = question + if default: + question_out += f' (Default: {default})' + response = '' + while True: + response = input(question_out + ' ').strip() + if not response and default: + return default + if numeric_only: + if not response.isnumeric(): + print("Invalid value, try again.") + continue + response = int(response) + if valid_responses and response not in valid_responses: + print("Invalid value, try again.") + continue + break + return response def ask_yes_no(question, default=False) -> bool: """Ask a yes/no question via input() and return their answer.""" |