}
}
}
//complete option value
else if(completeObject.isOption()) {
ProcessedOption currentOption = parser.getCommand().findOption(completeObject.getName());
if(currentOption == null)
currentOption = parser.getCommand().findLongOption(completeObject.getName());
//split the line on the option name. populate the object, then call the options completer
String displayName = currentOption.getDisplayName();
//this shouldnt happen
if(displayName == null) {
return;
}
String rest = completeOperation.getBuffer().substring(0, completeOperation.getBuffer().lastIndexOf( displayName));
try {
parser.getCommandPopulator().populateObject(command, parser.parse(rest), invocationProviders,
completeOperation.getAeshContext(), false);
}
//this should be ignored at some point
catch (CommandLineParserException | OptionValidatorException ignored) { }
if(currentOption.getCompleter() != null) {
CompleterInvocation completions =
invocationProviders.getCompleterProvider().enhanceCompleterInvocation(
new CompleterData(completeOperation.getAeshContext(), completeObject.getValue(), command));
currentOption.getCompleter().complete(completions);
completeOperation.addCompletionCandidatesTerminalString(completions.getCompleterValues());
completeOperation.setOffset( completeOperation.getCursor() - completeObject.getOffset());
completeOperation.setIgnoreOffset(completions.doIgnoreOffset());
completeOperation.setIgnoreStartsWith(completions.isIgnoreStartsWith());
if(completions.getCompleterValues().size() == 1) {
//if the contain spaces we need to add the number of spaces to the size
// of the value.length since they are chopped off during parsing
if(completeObject.getValue().indexOf(Parser.SPACE_CHAR) > 0) {
completeOperation.setOffset( completeOperation.getCursor() -
(completeObject.getOffset() + Parser.findNumberOfSpacesInWord(completeObject.getValue())));
}
if(completeOperation.getCompletionCandidates().get(0).containSpaces())
completeOperation.getCompletionCandidates().get(0).switchSpacesToEscapedSpaces();
completeOperation.doAppendSeparator( completions.isAppendSpace());
}
}
//only try to complete default values if completer is null
else if(currentOption.getDefaultValues().size() > 0) {
CompleterInvocation completions =
invocationProviders.getCompleterProvider().enhanceCompleterInvocation(
new CompleterData(completeOperation.getAeshContext(), completeObject.getValue(), command));
new DefaultValueOptionCompleter(currentOption.getDefaultValues()).complete(completions);
completeOperation.addCompletionCandidatesTerminalString(completions.getCompleterValues());
completeOperation.setOffset( completeOperation.getCursor() - completeObject.getOffset());
completeOperation.setIgnoreOffset(completions.doIgnoreOffset());
completeOperation.setIgnoreStartsWith(completions.isIgnoreStartsWith());