✨ Allow for use of named suggestion providers in @Flag annotated command method parameters, add methods to FlagContext to work with flag values as optionals
This commit is contained in:
parent
6d0301d9dd
commit
fc1a613463
10 changed files with 104 additions and 30 deletions
|
|
@ -23,15 +23,21 @@
|
|||
//
|
||||
package cloud.commandframework.annotations;
|
||||
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
/**
|
||||
* Indicates that the parameter should be treated like a {@link cloud.commandframework.arguments.flags.CommandFlag}.
|
||||
* If the parameter is a {@code boolean} then a presence flag will be created, else a value flag will be created
|
||||
* and the parser will be resolved the same way as it would for a {@link Argument}
|
||||
* <ul>
|
||||
* <li>If the parameter is a {@code boolean}, a presence flag will be created</li>
|
||||
* <li>If the parameter is of any other type, a value flag will be created and the parser
|
||||
* will resolve it in the same way that it would for an {@link Argument}</li>
|
||||
* </ul>
|
||||
*/
|
||||
@Target(ElementType.PARAMETER)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
|
|
@ -42,14 +48,14 @@ public @interface Flag {
|
|||
*
|
||||
* @return Flag name
|
||||
*/
|
||||
String value();
|
||||
@NonNull String value();
|
||||
|
||||
/**
|
||||
* Flag aliases
|
||||
*
|
||||
* @return Aliases
|
||||
*/
|
||||
String[] aliases() default "";
|
||||
@NonNull String[] aliases() default "";
|
||||
|
||||
/**
|
||||
* Name of the parser. Leave empty to use
|
||||
|
|
@ -57,13 +63,29 @@ public @interface Flag {
|
|||
*
|
||||
* @return Parser name
|
||||
*/
|
||||
String parserName() default "";
|
||||
@NonNull String parserName() default "";
|
||||
|
||||
/**
|
||||
* Name of the suggestions provider to use. If the string is left empty, the default
|
||||
* provider for the argument parser will be used. Otherwise,
|
||||
* the {@link cloud.commandframework.arguments.parser.ParserRegistry} instance in the
|
||||
* {@link cloud.commandframework.CommandManager} will be queried for a matching suggestion provider.
|
||||
* <p>
|
||||
* For this to work, the suggestion needs to be registered in the parser registry. To do this, use
|
||||
* {@link cloud.commandframework.arguments.parser.ParserRegistry#registerSuggestionProvider(String, BiFunction)}.
|
||||
* The registry instance can be retrieved using {@link cloud.commandframework.CommandManager#getParserRegistry()}.
|
||||
*
|
||||
* @return The name of the suggestion provider, or {@code ""} if the default suggestion provider for the argument parser
|
||||
* should be used instead
|
||||
* @since 1.2.0
|
||||
*/
|
||||
@NonNull String suggestions() default "";
|
||||
|
||||
/**
|
||||
* The argument description
|
||||
*
|
||||
* @return Argument description
|
||||
*/
|
||||
String description() default "";
|
||||
@NonNull String description() default "";
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue