-
-
Notifications
You must be signed in to change notification settings - Fork 74
Closed
Labels
enhancementNew feature or requestNew feature or requestimplemented for next releaseThis has been implemented in the current dev build for the next public releaseThis has been implemented in the current dev build for the next public release
Description
Please describe your suggestion
Optional arguments
Please supply examples of the desired inputs and outputs
Normal usage:
User enters this:
new CommandAPICommand("blah")
.withArgument(new IntegerArgument("int"))
.withOptionalArgument(new IntegerArgument("optional"), 10)
.executes((sender, args) -> {
int arg1 = (int) args[0];
int arg2 = (int) args[1]; // This is 10 if not existant
})
.register();Basically gets converted into this:
new CommandAPICommand("blah")
.withArgument(new IntegerArgument("int"))
.withArgument(new IntegerArgument("optional"))
.executes((sender, args) -> {
int arg1 = (int) args[0];
int arg2 = (int) args[1];
})
.register();and
new CommandAPICommand("blah")
.withArgument(new IntegerArgument("int"))
.executes((sender, args) -> {
int arg1 = (int) args[0];
int arg2 = (int) args[1]; // This is 10, args.length = 2
})
.register();Using annotations:
Either something like this:
@Subcommand("mycommand")
@Arg(name = "int", type = IntegerArgument.class)
@OptionalArg(name = "int", type = IntegerArgument.class, optional = "10")
public void onCommand(int arg1, int arg2) {
//...
}or something like this:
@Subcommand("mycommand")
@Arg(name = "int", type = IntegerArgument.class)
@Arg(name = "optional", type = IntegerArgument.class)
public void onCommand(int arg1, @Default("10") int arg2) {
//...
}Cons of this via annotations is that the value must be a string, primitive, enum, annotation or class, which is really restrictive.
demkom58
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or requestimplemented for next releaseThis has been implemented in the current dev build for the next public releaseThis has been implemented in the current dev build for the next public release