drink icon indicating copy to clipboard operation
drink copied to clipboard

Improved flag parsing and autocompletion for flags

Open MCMDEV opened this issue 3 years ago • 1 comments

I'd like to suggest some improvements on flag parsing and the autocompletion of flags. This is more of a collection of issues which are all closely related to one another. I have written a little report on the current situation and how I think an implementation could look like, hoping make the actual development a bit easier.

Current Behaviour:

First Example: This example uses three flags of different types Code:

    public void withFlags(@Sender Player sender, @Flag('s') String stringFlag, @Flag('i') int integerFlag, @Flag('b') boolean booleanFlag) {
        sender.sendMessage(ChatColor.YELLOW + "StringFlag: " + stringFlag + " IntegerFlag: " + integerFlag + " BooleanFlag: " + booleanFlag);
    }

Issues: Flags cannot be completed: noflags

In this example, there is always a boolean-value suggested after the second flag, regardless of order: boolerror boolerror2

Second Example: This example uses three booleans: Code:

    @Command(name = "bflagtest", desc = "A test command with a bunch of boolean flags")
    public void withBooleanFlags(@Sender Player sender, @Flag('a') boolean flag1, @Flag('b') boolean flag2, @Flag('c') boolean flag3) {
        sender.sendMessage(ChatColor.YELLOW + "flag1: " + flag1 + " flag2: " + flag2 + " flag3: " + flag3);
    }

Issues:

In here, the second suggestion is a boolean-value: image

When having a boolean-flag enclosed in two other boolean-flag, it does not get parsed: image

Group parsing is not supported: image

Proposal for expected behaviour:

My idea would be to mimick the behaviour of WorldEdit, as this libary is already inspired and their solution is good.

Tab-Completion of flags image

Tab-Completion of grouped flags: image

Ability to group boolean and value flags with one value flag being able to end a group: image

I know it's a lot to ask for, but it might be something to have on the radar.

MCMDEV avatar Feb 22 '21 18:02 MCMDEV

Definitely possible within the current implementation. I don't currently have time to look into this however, so feel free to open a PR. Should be able to just add a tab complete listener for strings starting with the flag key (-)

jonahseguin avatar May 14 '21 20:05 jonahseguin