Search in sources :

Example 1 with Argument

use of com.lexicalscope.jewel.cli.validation.Argument in project jewelcli by lexicalscope.

the class ArgumentPresenterImpl method presentArguments.

@Option
public O presentArguments(final OptionCollection validatedArguments) throws ArgumentValidationException {
    final Map<String, Object> argumentMap = new LinkedHashMap<String, Object>();
    final ValidationErrorBuilder validationErrorBuilder = new ValidationErrorBuilderImpl();
    for (final ParsedOptionSpecification optionSpecification : specification) {
        final ConvertTypeOfObject<?> convertTypeOfObject = converterTo(validationErrorBuilder, optionSpecification, optionSpecification.getMethod());
        putDefaultInMap(argumentMap, optionSpecification, convertTypeOfObject);
        final Argument argument = validatedArguments.getArgument(optionSpecification);
        if (argument != null) {
            putValuesInMap(argumentMap, optionSpecification, convertTypeOfObject, argument.getValues());
        }
    }
    if (specification.hasUnparsedSpecification()) {
        final UnparsedOptionSpecification unparsedSpecification = specification.getUnparsedSpecification();
        final ConvertTypeOfObject<?> convertTypeOfObject = converterTo(validationErrorBuilder, unparsedSpecification, unparsedSpecification.getMethod());
        putDefaultInMap(argumentMap, unparsedSpecification, convertTypeOfObject);
        if (!validatedArguments.getUnparsed().isEmpty()) {
            putValuesInMap(argumentMap, unparsedSpecification, convertTypeOfObject, validatedArguments.getUnparsed());
        }
    }
    validationErrorBuilder.validate();
    return argumentPresentingStrategy.presentArguments(argumentMap);
}
Also used : Argument(com.lexicalscope.jewel.cli.validation.Argument) ParsedOptionSpecification(com.lexicalscope.jewel.cli.specification.ParsedOptionSpecification) LinkedHashMap(java.util.LinkedHashMap) UnparsedOptionSpecification(com.lexicalscope.jewel.cli.specification.UnparsedOptionSpecification)

Aggregations

ParsedOptionSpecification (com.lexicalscope.jewel.cli.specification.ParsedOptionSpecification)1 UnparsedOptionSpecification (com.lexicalscope.jewel.cli.specification.UnparsedOptionSpecification)1 Argument (com.lexicalscope.jewel.cli.validation.Argument)1 LinkedHashMap (java.util.LinkedHashMap)1