Search in sources :

Example 1 with RoseCommandArgumentInfo

use of dev.rosewood.rosegarden.command.framework.RoseCommandArgumentInfo in project RoseGarden by Rosewood-Development.

the class EnumArgumentHandler method handleInternal.

@Override
protected T handleInternal(RoseCommandArgumentInfo argumentInfo, ArgumentParser argumentParser) {
    String input = argumentParser.next();
    T[] enumConstants = this.getHandledType().getEnumConstants();
    Optional<T> value = Stream.of(enumConstants).filter(x -> x.name().equalsIgnoreCase(input)).findFirst();
    if (!value.isPresent()) {
        String messageKey;
        StringPlaceholders placeholders = StringPlaceholders.builder("enum", this.handledType.getSimpleName()).addPlaceholder("input", input).addPlaceholder("types", Stream.of(enumConstants).map(x -> x.name().toLowerCase()).collect(Collectors.joining(", "))).build();
        if (enumConstants.length <= 10) {
            messageKey = "argument-handler-enum-list";
        } else {
            messageKey = "argument-handler-enum";
        }
        throw new HandledArgumentException(messageKey, placeholders);
    }
    return value.get();
}
Also used : RoseCommandArgumentInfo(dev.rosewood.rosegarden.command.framework.RoseCommandArgumentInfo) List(java.util.List) Stream(java.util.stream.Stream) Optional(java.util.Optional) RoseCommandArgumentHandler(dev.rosewood.rosegarden.command.framework.RoseCommandArgumentHandler) ArgumentParser(dev.rosewood.rosegarden.command.framework.ArgumentParser) StringPlaceholders(dev.rosewood.rosegarden.utils.StringPlaceholders) Collectors(java.util.stream.Collectors) RosePlugin(dev.rosewood.rosegarden.RosePlugin) StringPlaceholders(dev.rosewood.rosegarden.utils.StringPlaceholders)

Aggregations

RosePlugin (dev.rosewood.rosegarden.RosePlugin)1 ArgumentParser (dev.rosewood.rosegarden.command.framework.ArgumentParser)1 RoseCommandArgumentHandler (dev.rosewood.rosegarden.command.framework.RoseCommandArgumentHandler)1 RoseCommandArgumentInfo (dev.rosewood.rosegarden.command.framework.RoseCommandArgumentInfo)1 StringPlaceholders (dev.rosewood.rosegarden.utils.StringPlaceholders)1 List (java.util.List)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1