use of com.microsoft.azure.maven.utils.CustomTextIoStringListReader in project azure-maven-plugins by microsoft.
the class AbstractAzureMojo method selectSubscription.
protected String selectSubscription(Subscription[] subscriptions) throws AzureExecutionException {
if (subscriptions.length == 0) {
throw new AzureExecutionException("Cannot find any subscriptions in current account.");
}
if (subscriptions.length == 1) {
Log.info(String.format("There is only one subscription '%s' in your account, will use it automatically.", TextUtils.blue(SubscriptionOption.getSubscriptionName(subscriptions[0]))));
return subscriptions[0].getId();
}
final List<SubscriptionOption> wrapSubs = Arrays.stream(subscriptions).map(SubscriptionOption::new).sorted().collect(Collectors.toList());
final SubscriptionOption defaultValue = wrapSubs.get(0);
final TextIO textIO = TextIoFactory.getTextIO();
final SubscriptionOption subscriptionOptionSelected = new CustomTextIoStringListReader<SubscriptionOption>(textIO::getTextTerminal, null).withCustomPrompt(String.format("Please choose a subscription%s: ", highlightDefaultValue(defaultValue == null ? null : defaultValue.getSubscriptionName()))).withNumberedPossibleValues(wrapSubs).withDefaultValue(defaultValue).read("Available subscriptions:");
if (subscriptionOptionSelected == null) {
throw new AzureExecutionException("You must select a subscription.");
}
return subscriptionOptionSelected.getSubscription().getId();
}
Aggregations