8000 Optional arguments · Issue #162 · CommandAPI/CommandAPI · GitHub
[go: up one dir, main page]

Skip to content
Optional arguments #162
Closed
Closed
@JorelAli

Description

@JorelAli

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestimplemented for next releaseThis has been implemented in the current dev build for the next public release

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0