jonahseguin / drink

command framework and argument parser for spigot plugins
63 stars 19 forks source link

Improved flag parsing and autocompletion for flags #10

Open MCMDEV opened 3 years ago

MCMDEV commented 3 years ago

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.

jonahseguin commented 3 years ago

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 (-)