final boolean isMultiple = input instanceof ManyValued;
final boolean hasValue = (!InputType.CHECKBOX.equals(InputComponents.getInputType(input)) && !Boolean.class
.isAssignableFrom(input.getValueType()) && !boolean.class.isAssignableFrom(input.getValueType()));
try
{
OptionBuilder optionBuilder = new OptionBuilder();
optionBuilder.name(ShellUtil.shellifyName(inputName))
.addDefaultValue(defaultValue == null ? null : defaultValue.toString())
.description(input.getLabel())
.hasMultipleValues(isMultiple)
.hasValue(hasValue)
.type(input.getValueType());
if (input.isRequired() && !input.hasDefaultValue() && !input.hasValue())
{
optionBuilder.renderer(OptionRenderers.REQUIRED);
}
OptionCompleter<CompleterInvocation> completer = OptionCompleterFactory.getCompletionFor(
input, shellContext, converterFactory);
optionBuilder.completer(completer);
optionBuilder.activator(new OptionActivator()
{
@Override
public boolean isActivated(ProcessedCommand processedCommand)
{
return input.isEnabled();
}
}).validator(new OptionValidator<ValidatorInvocation<Object, Object>>()
{
@Override
public void validate(ValidatorInvocation<Object, Object> validatorInvocation)
throws OptionValidatorException
{
Object value = validatorInvocation.getValue();
InputComponents.setValueFor(converterFactory, input, value);
for (UIMessage message : command.validate(input))
{
if (message.getSource() == input && message.getSeverity() == Severity.ERROR)
{
throw new OptionValidatorException(message.getDescription());
}
}
}
}).converter(new Converter<Object, ConverterInvocation>()
{
@Override
public Object convert(ConverterInvocation converterInvocation) throws OptionValidatorException
{
String value = converterInvocation.getInput();
return InputComponents.convertToUIInputValue(converterFactory, input, value);
}
}).valueSeparator(' ');
if (input.getShortName() != InputComponents.DEFAULT_SHORT_NAME)
{
optionBuilder.shortName(input.getShortName());
}
ProcessedOption option = optionBuilder.create();
if (ARGUMENTS_INPUT_NAME.equals(input.getName()))
{
parameter.setArgument(option);
}
else