Skip to content

Commit

Permalink
Fix last argument optional not working #2
Browse files Browse the repository at this point in the history
  • Loading branch information
TBlueF committed Mar 22, 2024
1 parent 8b9081e commit 87ec6cd
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ void parse(ParseData<C, T> data) {
}
}
} else if (!subCommands.isEmpty()) {
if (isTreeOptional()) {
if (isSubTreeOptional()) {
gatherAllExecutables(data.getContext(), executable -> {
data.getResult().addMatch(new ParseMatch<>(executable, data.getContext(), data.getArguments(), data.getCommandStack()));
});
Expand All @@ -108,6 +108,12 @@ private void gatherAllExecutables(C context, Consumer<CommandExecutable<C, T>> c
subCommand.gatherAllExecutables(context, consumer);
}

private boolean isSubTreeOptional() {
for (Command<C, T> subCommand : subCommands)
if (!subCommand.isTreeOptional()) return false;
return true;
}

private boolean isTreeOptional() {
long now = System.currentTimeMillis();
if (lastTreeOptionalTime < now - 1000) {
Expand Down

0 comments on commit 87ec6cd

Please sign in to comment.