drink
drink copied to clipboard
Improved flag parsing and autocompletion for flags
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:
In this example, there is always a boolean-value suggested after the second flag, regardless of order:
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:
When having a boolean-flag enclosed in two other boolean-flag, it does not get parsed:
Group parsing is not supported:
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
Tab-Completion of grouped flags:
Ability to group boolean and value flags with one value flag being able to end a group:
I know it's a lot to ask for, but it might be something to have on the radar.
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 (-
)