cloud icon indicating copy to clipboard operation
cloud copied to clipboard

Allow flags to be used in the middle of commands.

Open MCMDEV opened this issue 3 years ago • 5 comments

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.

MCMDEV avatar Feb 23 '21 17:02 MCMDEV

I've also just noticed that WorldEdit's Fabric and Forge implementation allows flags anywhere and uses brigadier

MCMDEV avatar Feb 23 '21 17:02 MCMDEV

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.

Citymonstret avatar Jul 05 '21 10:07 Citymonstret

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?

solonovamax avatar Aug 26 '21 19:08 solonovamax

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?

Pablete1234 avatar Oct 14 '22 02:10 Pablete1234

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 suggest a, 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)

Pablete1234 avatar Oct 14 '22 06:10 Pablete1234