Fixed how optional commands work - we don't find an earlier command in the tree anymore.

This commit is contained in:
Nathan Adams 2017-06-30 09:17:07 +02:00
parent 9a3f987c97
commit 4af7274892
2 changed files with 3 additions and 5 deletions

View file

@ -89,9 +89,7 @@ public class CommandDispatcher<S> {
continue;
}
if (child.getCommand() != null) {
context.withCommand(child.getCommand());
}
context.withCommand(child.getCommand());
if (remaining.isEmpty()) {
return new ParseResults<>(context);
} else {

View file

@ -49,8 +49,8 @@ public class CommandDispatcherTest {
@SuppressWarnings("unchecked")
@Test
public void testCreateAndMergeCommands() throws Exception {
subject.register(literal("base").then(literal("foo")).executes(command));
subject.register(literal("base").then(literal("bar")).executes(command));
subject.register(literal("base").then(literal("foo").executes(command)));
subject.register(literal("base").then(literal("bar").executes(command)));
assertThat(subject.execute("base foo", source), is(42));
assertThat(subject.execute("base bar", source), is(42));