Search in sources :

Example 1 with ParsedOptionSpecification

use of com.lexicalscope.jewel.cli.specification.ParsedOptionSpecification in project jewelcli by lexicalscope.

the class OptionsSpecificationImpl method describeTo.

@Override
public void describeTo(final HelpMessage helpMessage) {
    if (!hasCustomApplicationName() && (!hasUnparsedSpecification() || getUnparsedSpecification().isHidden())) {
        helpMessage.noUsageInformation();
    } else {
        if (hasCustomApplicationName()) {
            helpMessage.hasUsageInformation(applicationName());
        } else {
            helpMessage.hasUsageInformation();
        }
        if (getMandatoryOptions().isEmpty()) {
            helpMessage.hasOnlyOptionalOptions();
        } else {
            helpMessage.hasSomeMandatoryOptions();
        }
        if (hasUnparsedSpecification() && !getUnparsedSpecification().isHidden()) {
            if (getUnparsedSpecification().isMultiValued()) {
                helpMessage.hasUnparsedMultiValuedOption(getUnparsedSpecification().getValueName());
            } else {
                helpMessage.hasUnparsedOption(getUnparsedSpecification().getValueName());
            }
        }
    }
    helpMessage.startOfOptions();
    for (final ParsedOptionSpecification specification : options) {
        if (!specification.isHidden()) {
            new ParsedOptionSummary(specification).describeOptionTo(helpMessage.option());
        }
    }
    helpMessage.endOfOptions();
}
Also used : ParsedOptionSpecification(com.lexicalscope.jewel.cli.specification.ParsedOptionSpecification)

Example 2 with ParsedOptionSpecification

use of com.lexicalscope.jewel.cli.specification.ParsedOptionSpecification 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)2 UnparsedOptionSpecification (com.lexicalscope.jewel.cli.specification.UnparsedOptionSpecification)1 Argument (com.lexicalscope.jewel.cli.validation.Argument)1 LinkedHashMap (java.util.LinkedHashMap)1