Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add allowAnyValue #576

Open
wants to merge 7 commits into
base: dev/dev
Choose a base branch
from
Open

Add allowAnyValue #576

wants to merge 7 commits into from

Conversation

stumper66
Copy link

Added a new option: allowAnyValue
This allows me to use ListArgumentBuilder for complex tab suggestions and simply passing all input so I can do my own validation.

This allowed me to create this command: https://youtu.be/q03_paw9Vzk

@stumper66 stumper66 changed the title Dev/dev Add allowAnyValue Jul 12, 2024
@@ -129,6 +141,9 @@ public ListArgumentBuilderFinished withStringMapper() {
* @return this list argument builder
*/
public ListArgumentBuilderFinished withMapper(Function<T, String> mapper) {
if (allowAnyValue && !(mapper instanceof StringTooltip)){
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This instanceof check is not necessary as it will always evaluate to true.

@@ -129,6 +141,9 @@ public ListArgumentBuilderFinished withStringMapper() {
* @return this list argument builder
*/
public ListArgumentBuilderFinished withMapper(Function<T, String> mapper) {
if (allowAnyValue && !(mapper instanceof StringTooltip)){
throw new IllegalArgumentException("allowAnyValue cannot be used with non-string mappers");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd say this should be something like:
allowAnyValue can only be set to true if a String mapper is used.

However, I do not know if that even is better so maybe we could wait for other opinions too.

Comment on lines +147 to +148
// should only be used with string mappers so we can ignore the cast warning
list.add((T) str);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// should only be used with string mappers so we can ignore the cast warning
list.add((T) str);
list.add(values.get(str));

As we have the map, I think we should use it instead of resorting to generic casts.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DerEchtePilz when I use the mapper it will give me a list of nulls. The only way I've found that works is to directly cast the string to T.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, that sounds like a bug to me that should get fixed. I am currently not available to test anything related to the ListArgument but using the mapper should most definitely not result in null values.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if it's a bug but maybe just a design flaw. The mapper value only works if the input is in the suggestions list.
That part might not be compatible with what we're trying to accomplish so that's why we made allowAnyValue only valid with strings since we need to cast the string input to T.

// should only be used with string mappers so we can ignore the cast warning
list.add((T) str);
}
else{
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
else{
else {

@@ -57,6 +57,20 @@ $$\downarrow$$

$$\downarrow$$

> ### Allowing any value (Optional)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this section I think we should mention that the allowAnyValue option only works for Strings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants