SHL-113: Don't report ambiguity on an exact match

This commit is contained in:
Eric Bottard
2014-04-02 16:33:09 +02:00
parent 6de9c8b1ae
commit 78082e25c7
2 changed files with 56 additions and 4 deletions

View File

@@ -103,6 +103,7 @@ public class SimpleParser implements Parser {
return optionsKeys;
}
@Override
public ParseResult parse(final String rawInput) {
synchronized (mutex) {
Assert.notNull(rawInput, "Raw input required");
@@ -124,12 +125,25 @@ public class SimpleParser implements Parser {
}
return null;
}
MethodTarget methodTarget = null;
if (matchingTargets.size() > 1) {
LOGGER.warning("Ambigious command '" + input + "' (for assistance press "
+ AbstractShell.completionKeys + " or type \"hint\" then hit ENTER)");
return null;
// Any prefix of a valid command will do. Don't fail if the user used
// the exact key of a command though.
for (MethodTarget candidate : matchingTargets) {
if (candidate.getKey().equals(input) || input.startsWith(candidate.getKey() + " ")) {
methodTarget = candidate;
break;
}
}
if (methodTarget == null) {
LOGGER.warning("Ambigious command '" + input + "' (for assistance press "
+ AbstractShell.completionKeys + " or type \"hint\" then hit ENTER)");
return null;
}
}
else {
methodTarget = matchingTargets.iterator().next();
}
MethodTarget methodTarget = matchingTargets.iterator().next();
// Argument conversion time
Annotation[][] parameterAnnotations = methodTarget.getMethod().getParameterAnnotations();
@@ -514,6 +528,7 @@ public class SimpleParser implements Parser {
return null; // Not a match
}
@Override
public int complete(String buffer, int cursor, final List<String> candidates) {
final List<Completion> completions = new ArrayList<Completion>();
int result = completeAdvanced(buffer, cursor, completions);
@@ -523,6 +538,7 @@ public class SimpleParser implements Parser {
return result;
}
@Override
public int completeAdvanced(String buffer, int cursor, final List<Completion> candidates) {
synchronized (mutex) {
Assert.notNull(buffer, "Buffer required");