Allow parser parameter annotations for flags as well (#315)

This commit is contained in:
Pasqual Koschmieder 2021-11-14 11:56:24 +01:00 committed by Jason
parent b111b8996c
commit 526ef2af61
2 changed files with 27 additions and 13 deletions

View file

@ -26,6 +26,8 @@ package cloud.commandframework.annotations;
import cloud.commandframework.Command;
import cloud.commandframework.CommandManager;
import cloud.commandframework.annotations.parsers.Parser;
import cloud.commandframework.annotations.specifier.Greedy;
import cloud.commandframework.annotations.specifier.Quoted;
import cloud.commandframework.annotations.specifier.Range;
import cloud.commandframework.annotations.suggestions.Suggestions;
import cloud.commandframework.arguments.StaticArgument;
@ -37,30 +39,28 @@ import cloud.commandframework.context.CommandContext;
import cloud.commandframework.meta.SimpleCommandMeta;
import io.leangen.geantyref.TypeToken;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
import java.util.Set;
import java.util.concurrent.CompletionException;
import java.util.function.BiFunction;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
class AnnotationParserTest {
@ -107,6 +107,8 @@ class AnnotationParserTest {
manager.executeCommand(new TestCommandSender(), "test 101").join());
manager.executeCommand(new TestCommandSender(), "flagcommand -p").join();
manager.executeCommand(new TestCommandSender(), "flagcommand --print --word peanut").join();
manager.executeCommand(new TestCommandSender(), "parserflagcommand -s \"Hello World\"").join();
manager.executeCommand(new TestCommandSender(), "parserflagcommand -s \"Hello World\" -o This is a test").join();
manager.executeCommand(new TestCommandSender(), "class method").join();
}
@ -244,6 +246,15 @@ class AnnotationParserTest {
}
}
@CommandMethod("parserflagcommand")
public void testQuotedFlags(
final TestCommandSender sender,
@Flag(value = "sentence", aliases = "s") @Quoted final String sentence,
@Flag(value = "other", aliases = "o") @Greedy final String otherStuff
) {
System.out.println(sentence + (otherStuff == null ? "" : " " + otherStuff));
}
@CommandMethod("namedsuggestions <input>")
public void testNamedSuggestionProviders(
@Argument(value = "input", suggestions = "some-name") final String argument