Skip to content

Commit

Permalink
FORGE-1155: Validating input
Browse files Browse the repository at this point in the history
  • Loading branch information
gastaldi committed Oct 14, 2013
1 parent 63623f8 commit 8776385
Showing 1 changed file with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@
import org.jboss.aesh.cl.internal.ProcessedOption;
import org.jboss.aesh.cl.parser.CommandLineParser;
import org.jboss.aesh.cl.validator.OptionValidator;
import org.jboss.aesh.cl.validator.OptionValidatorException;
import org.jboss.forge.addon.convert.ConverterFactory;
import org.jboss.forge.addon.shell.aesh.completion.OptionCompleterFactory;
import org.jboss.forge.addon.shell.ui.ShellContext;
import org.jboss.forge.addon.shell.ui.ShellValidationContext;
import org.jboss.forge.addon.shell.util.ShellUtil;
import org.jboss.forge.addon.ui.UICommand;
import org.jboss.forge.addon.ui.hints.InputType;
Expand Down Expand Up @@ -61,8 +63,8 @@ public CommandLineParser generateParser(UICommand command, ShellContext shellCon
return new ForgeCommandLineParser(processedCommand, this, inputs);
}

private ProcessedCommand generateCommand(UICommand command, ShellContext shellContext,
Map<String, InputComponent<?, Object>> inputs)
private ProcessedCommand generateCommand(final UICommand command, final ShellContext shellContext,
final Map<String, InputComponent<?, Object>> inputs)
{
UICommandMetadata metadata = command.getMetadata(shellContext);
ProcessedCommand parameter = new ProcessedCommand(ShellUtil.shellifyName(metadata.getName()),
Expand Down Expand Up @@ -99,7 +101,14 @@ public boolean isEnabled(ProcessedCommand command)
@Override
public void validate(Object value) throws org.jboss.aesh.cl.validator.OptionValidatorException
{
// TODO: Call input.validate?
InputComponents.setValueFor(converterFactory, input, value);
ShellValidationContext validationContext = new ShellValidationContext(shellContext);
input.validate(validationContext);
List<String> errors = validationContext.getErrors();
if (!errors.isEmpty())
{
throw new OptionValidatorException(errors.get(0));
}
}
});
optionBuilder.converter(new CLConverter<Object>()
Expand Down

0 comments on commit 8776385

Please sign in to comment.