in source/idea/idea-sdk/src/ideasdk/user_input/framework.py [0:0]
def build(self, review_mode: bool = False) -> Optional[Union[List[Dict], Dict]]:
if self.can_skip(review_mode):
return None
param_type = self.param_type
questions = []
num_choices = 0
default = self.default()
def common() -> Dict:
help_text = self.help_text
if help_text is not None:
help_text = f'({help_text})'
return {
'type': str(param_type),
'name': self.name,
'default': default,
'message': self.get_prompt(self.description),
'filter': self.get_filter(),
'qmark': self.unicode_icon,
'instruction': help_text
}
def eval_select_or_text(result) -> bool:
return result.get(self.name) == constants.SELECT_CHOICE_OTHER
if param_type in (SocaUserInputParamType.SELECT,
SocaUserInputParamType.RAW_SELECT,
SocaUserInputParamType.SELECT_OR_TEXT):
choices = self.get_choices()
choices_ = []
default_choice = None
for choice in choices:
choice_ = Choice(
title=choice.title,
value=choice.value,
disabled=choice.disabled,
checked=choice.checked
)
if choice.value == default:
default_choice = choice_
choices_.append(choice_)
num_choices = len(choices_)
param_type_ = param_type
if param_type_ == SocaUserInputParamType.SELECT_OR_TEXT:
if num_choices > 0:
param_type_ = SocaUserInputParamType.SELECT
choices_.append(Separator())
choices_.append(Choice(
title=constants.SELECT_CHOICE_OTHER,
value=constants.SELECT_CHOICE_OTHER
))
if num_choices > 0:
questions.append({**common(), **{
'type': str(param_type_),
'choices': choices_,
'default': default_choice
}})
else:
param_type = SocaUserInputParamType.TEXT
if param_type in (SocaUserInputParamType.TEXT,
SocaUserInputParamType.SELECT_OR_TEXT):
override = {
'validate': self.get_validator(),
'multiline': self.multiline
}
if param_type == SocaUserInputParamType.SELECT_OR_TEXT:
if self.description2:
message = self.get_prompt(self.description2)
else:
prompt = self.param.try_convert_select_to_enter(self.description)
message = self.get_prompt(prompt)
override['type'] = str(SocaUserInputParamType.TEXT)
override['message'] = message
if num_choices > 0:
override['when'] = eval_select_or_text
questions.append({**common(), **override})
override = None
if param_type == SocaUserInputParamType.PASSWORD:
override = {
'validate': self.get_validator()
}
elif param_type == SocaUserInputParamType.PATH:
override = {
'validate': self.get_validator()
}
elif param_type == SocaUserInputParamType.CONFIRM:
override = {
'type': 'confirm',
'auto_enter': self.auto_enter
}
elif param_type == SocaUserInputParamType.CHECKBOX:
choices = self.get_choices()
choices_ = []
defaults = Utils.get_as_list(self.default(), [])
for choice in choices:
choice_ = Choice(
title=choice.title,
value=choice.value,
disabled=choice.disabled,
checked=choice.value in defaults
)
choices_.append(choice_)
override = {
'choices': choices_,
'validate': self.get_validator()
}
elif param_type == SocaUserInputParamType.AUTOCOMPLETE:
choices = self.get_choices()
choices_ = []
for choice in choices:
value = choice.title
if Utils.is_empty(value):
value = str(choice.value)
if Utils.is_empty(value):
continue
choices_.append(value)
override = {
'choices': choices_,
'default': default,
'validate': self.get_validator()
}
if len(questions) > 0:
return questions
if override is None:
return None
questions.append({**common(), **override})
return questions