in azure-spring-cloud-maven-plugin/src/main/java/com/microsoft/azure/maven/springcloud/config/ConfigurationPrompter.java [91:128]
public <T> T handleSelectOne(String templateId, List<T> options, T defaultEntity, Function<T, String> getNameFunc)
throws IOException, InvalidConfigurationException {
final Map<String, Object> variables = createVariableTables(templateId);
final boolean isRequired = TemplateUtils.evalBoolean("required", variables);
if (options.size() == 0) {
if (isRequired) {
throw new InvalidConfigurationException(TemplateUtils.evalText("message.empty_options", variables));
}
final String warningMessage = TemplateUtils.evalText("message.empty_options", variables);
if (StringUtils.isNotBlank(warningMessage)) {
log.warn(warningMessage);
}
return null;
}
final boolean autoSelect = TemplateUtils.evalBoolean("auto_select", variables);
if (options.size() == 1) {
if (autoSelect) {
log.info(TemplateUtils.evalText("message.auto_select", variables));
return options.get(0);
}
if (!this.prompt.promoteYesNo(TemplateUtils.evalText("promote.one", variables),
/*
* if only one options is available, when it is required, select it by default
*/
isRequired, isRequired)) {
if (isRequired) {
throw new InvalidConfigurationException(TemplateUtils.evalText("message.select_none", variables));
}
return null;
}
return options.get(0);
}
if (defaultEntity == null && variables.containsKey("default_index")) {
defaultEntity = options.get((Integer) variables.get("default_index"));
}
return prompt.promoteSingleEntity(TemplateUtils.evalText("promote.header", variables), TemplateUtils.evalText("promote.many", variables),
options, defaultEntity, getNameFunc, isRequired);
}