in gcpdiag/runbook/output/terminal_output.py [0:0]
def prompt(self,
message: str,
kind: str = '',
options: dict = None,
choice_msg: str = 'Choose an option: ',
non_interactive: bool = None) -> Any:
"""
For informational update and getting a response from user
"""
non_interactive = non_interactive or config.get(INTERACTIVE_MODE)
if non_interactive:
return
self.terminal_print_line(text='' + '[' + self.term.green(kind) + ']: ' +
f'{message}')
self.default_answer = False
self.answer = None
options_text = '\n'
try:
if kind in constants.HUMAN_TASK and not options:
for option, description in constants.HUMAN_TASK_OPTIONS.items():
options_text += '[' + self.term.green(
f'{option}') + ']' + f' - {description}\n'
if kind in constants.CONFIRMATION and not options:
for option, description in constants.CONFIRMATION_OPTIONS.items():
options_text += '[' + self.term.green(
f'{option}') + ']' + f' - {description}\n'
if (kind in constants.CONFIRMATION or kind in constants.HUMAN_TASK) \
and options:
for option, description in options.items():
options_text += '[' + self.term.green(
f'{option}') + ']' + f' - {description}\n'
if options_text:
self.terminal_print_line(text=textwrap.indent(options_text, ' '))
self.answer = input(textwrap.indent(choice_msg, ' '))
except EOFError:
return self.answer
# pylint:disable=g-explicit-bool-comparison, We explicitly want to
# distinguish between empty string and None.
if self.answer == '':
# User just hit enter, return default.
return self.default_answer
elif self.answer is None:
return self.answer
elif self.answer.strip().lower() in ['s', 'stop']:
return constants.STOP
elif self.answer.strip().lower() in ['c', 'continue']:
return constants.CONTINUE
elif self.answer.strip().lower() in ['u', 'uncertain']:
return constants.UNCERTAIN
elif self.answer.strip().lower() in ['r', 'retest']:
return constants.RETEST
elif self.answer.strip().lower() in ['y', 'yes']:
return constants.YES
elif self.answer.strip().lower() in ['n', 'no']:
return constants.NO
elif self.answer.strip().lower() not in [
's', 'stop', 'c', 'continue', 'r', 'retest'
]:
return self.answer.strip()
return