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();
}
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);
}
Aggregations