Fixed how optional commands work - we don't find an earlier command in the tree anymore.
This commit is contained in:
@@ -89,9 +89,7 @@ public class CommandDispatcher<S> {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (child.getCommand() != null) {
|
|
||||||
context.withCommand(child.getCommand());
|
context.withCommand(child.getCommand());
|
||||||
}
|
|
||||||
if (remaining.isEmpty()) {
|
if (remaining.isEmpty()) {
|
||||||
return new ParseResults<>(context);
|
return new ParseResults<>(context);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -49,8 +49,8 @@ public class CommandDispatcherTest {
|
|||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Test
|
@Test
|
||||||
public void testCreateAndMergeCommands() throws Exception {
|
public void testCreateAndMergeCommands() throws Exception {
|
||||||
subject.register(literal("base").then(literal("foo")).executes(command));
|
subject.register(literal("base").then(literal("foo").executes(command)));
|
||||||
subject.register(literal("base").then(literal("bar")).executes(command));
|
subject.register(literal("base").then(literal("bar").executes(command)));
|
||||||
|
|
||||||
assertThat(subject.execute("base foo", source), is(42));
|
assertThat(subject.execute("base foo", source), is(42));
|
||||||
assertThat(subject.execute("base bar", source), is(42));
|
assertThat(subject.execute("base bar", source), is(42));
|
||||||
|
|||||||
Reference in New Issue
Block a user