SpongeAPI icon indicating copy to clipboard operation
SpongeAPI copied to clipboard

Wrong ArgumentParseException when using custom CommandCallables as child commands

Open ImMorpheus opened this issue 5 years ago • 0 comments

When creating child commands using custom CommandCallables a different "usage" message is displayed.

Code to reproduce:

Sponge.getCommandManager().register(this,
        CommandSpec.builder()
                .child(new CommandCallable() {
                    @Override
                    public CommandResult process(CommandSource source, String arguments) throws CommandException {
                        final CommandArgs args = new CommandArgs(arguments, InputTokenizer.spaceSplitString().tokenize(arguments, false));
                        final CommandContext context = new CommandContext();

                        GenericArguments.seq(GenericArguments.integer(Text.of("int"))).parse(source, args, context);
                        if (args.hasNext()) {
                            args.next();
                            throw args.createError(Text.of("Too many arguments!"));
                        }
                        return CommandResult.success();
                    }

                    @Override
                    public List<String> getSuggestions(CommandSource source, String arguments, @Nullable Location<World> targetPosition) throws CommandException {
                        return Collections.emptyList();
                    }

                    @Override
                    public boolean testPermission(CommandSource source) {
                        return true;
                    }

                    @Override
                    public Optional<Text> getShortDescription(CommandSource source) {
                        return Optional.empty();
                    }

                    @Override
                    public Optional<Text> getHelp(CommandSource source) {
                        return Optional.empty();
                    }

                    @Override
                    public Text getUsage(CommandSource source) {
                        return Text.of();
                    }
                }, "child")
                .child(CommandSpec.builder()
                        .arguments(GenericArguments.integer(Text.of("integer")))
                        .executor((src, args) -> CommandResult.success())
                        .build(), "spec"
                )
                .build(),
        "argtest");

/argtest spec ->

Not enough arguments!\nspec\n^
Usage: /argtest spec <integer>

/argtest child ->

Not enough arguments!
Usage: /argtest spec|child

I'd expect to get the same message for both commands but the second error is the same you get when using /argtest.

ImMorpheus avatar Jun 06 '20 17:06 ImMorpheus