Fix flags not tab-completing unless string is empty (#460)
This commit is contained in:
parent
cba9b5f079
commit
90b63e53f3
2 changed files with 39 additions and 6 deletions
|
|
@ -41,7 +41,6 @@ import cloud.commandframework.keys.SimpleCloudKey;
|
||||||
import cloud.commandframework.permission.CommandPermission;
|
import cloud.commandframework.permission.CommandPermission;
|
||||||
import cloud.commandframework.permission.OrPermission;
|
import cloud.commandframework.permission.OrPermission;
|
||||||
import cloud.commandframework.types.tuples.Pair;
|
import cloud.commandframework.types.tuples.Pair;
|
||||||
import io.leangen.geantyref.GenericTypeReflector;
|
|
||||||
import io.leangen.geantyref.TypeToken;
|
import io.leangen.geantyref.TypeToken;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
@ -613,10 +612,6 @@ public final class CommandTree<C> {
|
||||||
if (!lastFlag.isPresent()) {
|
if (!lastFlag.isPresent()) {
|
||||||
commandContext.remove(FlagArgument.FLAG_META_KEY);
|
commandContext.remove(FlagArgument.FLAG_META_KEY);
|
||||||
}
|
}
|
||||||
} else if (GenericTypeReflector.erase(child.getValue().getValueType().getType()).isArray()) {
|
|
||||||
while (commandQueue.size() > 1) {
|
|
||||||
commandQueue.remove();
|
|
||||||
}
|
|
||||||
} else if (commandQueue.size() <= child.getValue().getParser().getRequestedArgumentCount()) {
|
} else if (commandQueue.size() <= child.getValue().getParser().getRequestedArgumentCount()) {
|
||||||
for (int i = 0; i < child.getValue().getParser().getRequestedArgumentCount() - 1
|
for (int i = 0; i < child.getValue().getParser().getRequestedArgumentCount() - 1
|
||||||
&& commandQueue.size() > 1; i++) {
|
&& commandQueue.size() > 1; i++) {
|
||||||
|
|
@ -636,7 +631,7 @@ public final class CommandTree<C> {
|
||||||
} else if (child.getValue() instanceof CompoundArgument) {
|
} else if (child.getValue() instanceof CompoundArgument) {
|
||||||
return this.directSuggestions(commandContext, child, ((LinkedList<String>) commandQueue).getLast());
|
return this.directSuggestions(commandContext, child, ((LinkedList<String>) commandQueue).getLast());
|
||||||
}
|
}
|
||||||
} else if (commandQueue.size() == 1 && commandQueue.peek().isEmpty()) {
|
} else if (commandQueue.size() == 1) {
|
||||||
return this.directSuggestions(commandContext, child, commandQueue.peek());
|
return this.directSuggestions(commandContext, child, commandQueue.peek());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@
|
||||||
//
|
//
|
||||||
package cloud.commandframework;
|
package cloud.commandframework;
|
||||||
|
|
||||||
|
import cloud.commandframework.arguments.CommandArgument;
|
||||||
import cloud.commandframework.arguments.compound.ArgumentTriplet;
|
import cloud.commandframework.arguments.compound.ArgumentTriplet;
|
||||||
import cloud.commandframework.arguments.parser.ArgumentParseResult;
|
import cloud.commandframework.arguments.parser.ArgumentParseResult;
|
||||||
import cloud.commandframework.arguments.standard.BooleanArgument;
|
import cloud.commandframework.arguments.standard.BooleanArgument;
|
||||||
|
|
@ -37,8 +38,10 @@ import cloud.commandframework.types.tuples.Triplet;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import org.junit.Ignore;
|
||||||
import org.junit.jupiter.api.Assertions;
|
import org.junit.jupiter.api.Assertions;
|
||||||
import org.junit.jupiter.api.BeforeAll;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
|
import org.junit.jupiter.api.Disabled;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static cloud.commandframework.util.TestUtils.createManager;
|
import static cloud.commandframework.util.TestUtils.createManager;
|
||||||
|
|
@ -635,6 +638,41 @@ public class CommandSuggestionsTest {
|
||||||
assertThat(suggestions6).isEmpty();
|
assertThat(suggestions6).isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testTextFlagCompletion() {
|
||||||
|
// Arrange
|
||||||
|
final CommandManager<TestCommandSender> manager = createManager();
|
||||||
|
manager.setSetting(CommandManager.ManagerSettings.LIBERAL_FLAG_PARSING, true);
|
||||||
|
manager.command(
|
||||||
|
manager.commandBuilder("command")
|
||||||
|
.flag(manager.flagBuilder("flag").withAliases("f")
|
||||||
|
.withArgument(EnumArgument.of(TestEnum.class, "test")).build())
|
||||||
|
.flag(manager.flagBuilder("flog").build())
|
||||||
|
);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
final List<String> suggestions1 = suggest(manager, "command ");
|
||||||
|
final List<String> suggestions2 = suggest(manager, "command --");
|
||||||
|
final List<String> suggestions3 = suggest(manager, "command --f");
|
||||||
|
final List<String> suggestions4 = suggest(manager, "command --fla");
|
||||||
|
final List<String> suggestions5 = suggest(manager, "command -f");
|
||||||
|
final List<String> suggestions6 = suggest(manager, "command -");
|
||||||
|
|
||||||
|
final List<String> suggestions7 = suggest(manager, "command -f ");
|
||||||
|
final List<String> suggestions8 = suggest(manager, "command -f b");
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
assertThat(suggestions1).containsExactly("--flag", "--flog", "-f");
|
||||||
|
assertThat(suggestions2).containsExactly("--flag", "--flog");
|
||||||
|
assertThat(suggestions3).containsExactly("--flag", "--flog");
|
||||||
|
assertThat(suggestions4).containsExactly("--flag");
|
||||||
|
assertThat(suggestions5).containsExactly("-f");
|
||||||
|
assertThat(suggestions6).containsExactly("--flag", "--flog", "-f");
|
||||||
|
assertThat(suggestions7).containsExactly("foo", "bar");
|
||||||
|
assertThat(suggestions8).containsExactly("bar");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private List<String> suggest(CommandManager<TestCommandSender> manager, String command) {
|
private List<String> suggest(CommandManager<TestCommandSender> manager, String command) {
|
||||||
return manager.suggest(new TestCommandSender(), command);
|
return manager.suggest(new TestCommandSender(), command);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue