Search in sources :

Example 1 with CustomTextIoStringListReader

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();
}
Also used : SubscriptionOption(com.microsoft.azure.maven.model.SubscriptionOption) AzureExecutionException(com.microsoft.azure.toolkit.lib.common.exception.AzureExecutionException) CustomTextIoStringListReader(com.microsoft.azure.maven.utils.CustomTextIoStringListReader) TextIO(org.beryx.textio.TextIO)

Aggregations

SubscriptionOption (com.microsoft.azure.maven.model.SubscriptionOption)1 CustomTextIoStringListReader (com.microsoft.azure.maven.utils.CustomTextIoStringListReader)1 AzureExecutionException (com.microsoft.azure.toolkit.lib.common.exception.AzureExecutionException)1 TextIO (org.beryx.textio.TextIO)1