Skip to content

Commit

Permalink
OptionCompleter fails if command has more than one arg, fixed.
Browse files Browse the repository at this point in the history
  • Loading branch information
mattirn committed Nov 20, 2019
1 parent ed0d946 commit 8737ca2
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions builtins/src/main/java/org/jline/builtins/Completers.java
Expand Up @@ -739,7 +739,7 @@ public void complete(LineReader reader, final ParsedLine commandLine, List<Candi
boolean valueCandidates = false;
if (commandOptions != null) {
boolean longOption = buffer.startsWith("--");
for (Map.Entry<String,String> entry: commandOptions.apply(words.get(0)).entrySet()) {
for (Map.Entry<String,String> entry: commandOptions.apply(Parser.getCommand(words.get(0))).entrySet()) {
if (entry.getKey().startsWith(buffer)) {
addbuff = false;
}
Expand Down Expand Up @@ -799,13 +799,15 @@ public void complete(LineReader reader, final ParsedLine commandLine, List<Candi
candidates.add(new Candidate(buffer, buffer, null, null, null, null, true));
}
} else if (argsCompleters.size() > 1) {
int args = 0;
int args = -1;
for (int i = startPos; i < words.size(); i++) {
if (!words.get(i).startsWith("-")) {
args++;
}
}
if (args < argsCompleters.size()) {
if (args == -1) { // alternatively could set argumentCompleter strict = false;
candidates.add(new Candidate(buffer, buffer, null, null, null, null, true));
} else if (args < argsCompleters.size()) {
argsCompleters.get(args).complete(reader, commandLine, candidates);
} else {
argsCompleters.get(argsCompleters.size() - 1).complete(reader, commandLine, candidates);
Expand Down

1 comment on commit 8737ca2

@mattirn
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.