question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

(String) argument suggestions do not show up because argument succeeds parsing

See original GitHub issue

I didn’t know whether to put this in the PR or as a separate issue, so I’m putting it out here.

Note: no brigadier is used

https://github.com/Incendo/cloud/blob/1.2.0-dev/cloud-core/src/main/java/cloud/commandframework/CommandTree.java#L508

In the CommandTree suggestions code, the following is done when providing suggestions for non-static arguments:

            // START: Preprocessing
            final ArgumentParseResult<Boolean> preParseResult = child.getValue().preprocess(
                    commandContext,
                    commandQueue
            );
            if (preParseResult.getFailure().isPresent() || !preParseResult.getParsedValue().orElse(false)) {
                final String value = stringOrEmpty(commandQueue.peek());
                commandContext.setCurrentArgument(child.getValue());
                return child.getValue().getSuggestionsProvider().apply(commandContext, value);
            }
            // END: Preprocessing

            // START: Parsing
            commandContext.setCurrentArgument(child.getValue());
            final ArgumentParseResult<?> result = child.getValue().getParser().parse(commandContext, commandQueue);
            if (result.getParsedValue().isPresent()) {
                commandContext.store(child.getValue().getName(), result.getParsedValue().get());
                return this.getSuggestions(commandContext, commandQueue, child);
            } else if (result.getFailure().isPresent()) {
                final String value = stringOrEmpty(commandQueue.peek());
                commandContext.setCurrentArgument(child.getValue());
                return child.getValue().getSuggestionsProvider().apply(commandContext, value);
            }

It is difficult to see the problem, until you start using suggestion providers. The problem is that when you add a StringArgument with a custom suggestion provider, the parsing will succeed even when the value being parsed isn’t one of the suggestions. As a result, players can start typing and see the full list, but the moment they type one more character, all suggestions disappear.

I will probably fix this in my PR https://github.com/Incendo/cloud/pull/142 but need to know whether this was intentional behavior.

My proposed fix will be to not call the deeper getSuggestions() function when the number of remaining elements in the command queue is 0, and instead do the (parse) failure case.

The only workaround right now is to not use the suggestion provider, but make a custom argument parser which rejects values that aren’t part of the enumeration. That’s not a solution for people that want to accept non-suggested input.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
Proximystcommented, Nov 23, 2020

Just rebase onto your other branch; when we merge it, either you rebase this, or we will do it for you if/when this is merged.

0reactions
bergerkillercommented, Nov 23, 2020

Is there a way to make one PR a prerequisite for another PR? I’ll put it in it’s own PR, but need to refer to it from https://github.com/Incendo/cloud/pull/142 otherwise the commit will show up twice, which is weird.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Looking for a Command Line Argument Parser for .NET [closed]
My personal favourite 3rd party commandline parsing library is Command Line Parser and I assume this is the one you are referring to....
Read more >
Parsing arguments and building values — Python 3.11.1 ...
On Python 3.9 and older, the type of the length argument is Py_ssize_t if the ... The Python string must not contain embedded...
Read more >
Argument Parsing — Documentação Sponge 7.4.0
The Command Builder API comes with a powerful argument parser. It converts the string input to java base types (integers, booleans, strings) or...
Read more >
5.3 Internals of a simple Parser function
The actual parsing logic is completely straightforward: On line 5 the parser calls the CharStream's Skip method with the argument str . If...
Read more >
Fancy Argument Parsing — c-extension-tutorial documentation
PyObject* kwargs : A dictionary of keyword arguments or NULL if no keyword ... should match up with the number of arguments specified...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found