Optional arguments
See original GitHub issuePlease 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.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:10 (5 by maintainers)
Top Results From Across the Web
Using Python Optional Arguments When Defining Functions
In this section, you'll learn how to define a function that takes an optional argument. Functions with optional arguments offer more flexibility in...
Read more >python - How do I define a function with optional arguments?
Just use the *args parameter, which allows you to pass as many arguments as you want after your a,b,c . You would have...
Read more >Optional Arguments (Guile Reference Manual) - GNU.org
6.7.4 Optional Arguments. Scheme procedures, as defined in R5RS, can either handle a fixed number of actual arguments, or a fixed number of...
Read more >Python Optional Arguments: A How-To Guide - Career Karma
A Python optional argument is an argument with a default value. You can specify a default value for an argument using the assignment...
Read more >C++ Default Parameters - W3Schools
A parameter with a default value, is often known as an "optional parameter". From the example above, country is an optional parameter and...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
It would be very good to get this implemented (or at least have made significant progress on this) for a 8.5.0 release due late July or early August.
Thanks! I got it.