cloud
cloud copied to clipboard
Allow flags to be used in the middle of commands.
I am aware of whats written in #75 but I think its incredibly annoying. Maybe it's possible to allow this by excluding brigadier from parsing flags or disable brigadier alltogether by an option.
I've also just noticed that WorldEdit's Fabric and Forge implementation allows flags anywhere and uses brigadier
If anyone can figure out a good solution to this that doesn't inflate the command tree into insane sizes, then I'd be more than willing to add this to the library.
The only solution I've been able to think of so far includes attaching all permutations of the flags, something along the lines of:
/foo a b c —d —e
/foo a —d b c —e
/foo a —d b —e c
/foo a —d —e —b c
/foo a b c —e —d
/foo a —e b c —e
/foo a —e b —d c
/foo a —e —d b c
This will be fine, as long as people don't have an insane amount of flags in the tree.
Perhaps when querying the flag list in the tree, it gets the flag list of the parent node and adds it to its own internal flag list?
Would making the "permutations" be /foo [flags] a [flags] b [flags] c [flags]
feasible? simply an optional node in between each param that tries to parse flags, the flags parser being the one in charge for checking for as many flags as there are there?
I've put together a proof-of-concept version that seems to pass all tests doing basically what i described above in commit https://github.com/Incendo/cloud/commit/430beb7e759c72b8949db276fe985f44f1c72fea
- The command when being added to the tree inserts the flags argument between every argument
- The flag parser was changed to support not parsing anything (non-greedy flag parsing, only parsing if the text in the queue starts with "-").
- A small workarround is required for tab suggestions (ie:
/foo
has to suggesta
, but normally only [flags] would be suggested) to add the next param suggestions if it's a flag.
It is very much just a proof of concept, it does a few dirty things, and i believe it will have some bugs (probably duplicate flags aren't detected since the HashSet is created each time parse is called, but should be easy to workarround if state is fully obtained from command context)