Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
import cloud.commandframework.permission.CommandPermission;
import cloud.commandframework.permission.OrPermission;
import cloud.commandframework.types.tuples.Pair;
import io.leangen.geantyref.GenericTypeReflector;
import io.leangen.geantyref.TypeToken;
import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -613,10 +612,6 @@ private CommandTree(final @NonNull CommandManager<C> commandManager) {
if (!lastFlag.isPresent()) {
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()) {
for (int i = 0; i < child.getValue().getParser().getRequestedArgumentCount() - 1
&& commandQueue.size() > 1; i++) {
Expand All @@ -636,7 +631,7 @@ private CommandTree(final @NonNull CommandManager<C> commandManager) {
} else if (child.getValue() instanceof CompoundArgument) {
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());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
//
package cloud.commandframework;

import cloud.commandframework.arguments.CommandArgument;
import cloud.commandframework.arguments.compound.ArgumentTriplet;
import cloud.commandframework.arguments.parser.ArgumentParseResult;
import cloud.commandframework.arguments.standard.BooleanArgument;
Expand All @@ -37,8 +38,10 @@
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.junit.Ignore;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

import static cloud.commandframework.util.TestUtils.createManager;
Expand Down Expand Up @@ -635,6 +638,41 @@ void testFlagYieldingStringArrayWithLiberalFlagArgument() {
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) {
return manager.suggest(new TestCommandSender(), command);
}
Expand Down