diff options
author | John Estabrook <jestabro@vyos.io> | 2023-10-31 12:53:52 -0500 |
---|---|---|
committer | John Estabrook <jestabro@vyos.io> | 2023-12-16 20:37:10 -0600 |
commit | e812d494d16a29783254fb1edc0894e054184dcc (patch) | |
tree | 464b18fc9276fea7c835c4186697679528c3b4cc /python/vyos | |
parent | 5949df2ffe1a4bb19171f2bc2bfd3a1026101aee (diff) | |
download | vyos-1x-e812d494d16a29783254fb1edc0894e054184dcc.tar.gz vyos-1x-e812d494d16a29783254fb1edc0894e054184dcc.zip |
image: T4516: restore select entry to set/delete image
(cherry picked from commit 9ffa3e82d951756696367578dd5e82ef0f690065)
Diffstat (limited to 'python/vyos')
-rw-r--r-- | python/vyos/utils/io.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/python/vyos/utils/io.py b/python/vyos/utils/io.py index 8790cbaac..e34a1ba32 100644 --- a/python/vyos/utils/io.py +++ b/python/vyos/utils/io.py @@ -72,3 +72,22 @@ def is_dumb_terminal(): """Check if the current TTY is dumb, so that we can disable advanced terminal features.""" import os return os.getenv('TERM') in ['vt100', 'dumb'] + +def select_entry(l: list, list_msg: str = '', prompt_msg: str = '') -> str: + """Select an entry from a list + + Args: + l (list): a list of entries + list_msg (str): a message to print before listing the entries + prompt_msg (str): a message to print as prompt for selection + + Returns: + str: a selected entry + """ + en = list(enumerate(l, 1)) + print(list_msg) + for i, e in en: + print(f'\t{i}: {e}') + select = ask_input(prompt_msg, numeric_only=True, + valid_responses=range(1, len(l)+1)) + return next(filter(lambda x: x[0] == select, en))[1] |