-
Notifications
You must be signed in to change notification settings - Fork 447
Pluggable enum conversion facility for picocli. #2449
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the pull request. I will look in more detail later (so I may have more feedback later) but overall it looks good.
Please add documentation and tests and I think this can be merged.
Please add a section "Custom Enum Type Converters" to the user manual
(located here: docs/index.adoc - HTML is auto-generated from this).
I suggest after section === Handling Invalid Input and
before section === Option-specific Type Converters.
Also, please provide JUnit tests that verify at least
- that registering a custom enum type converter will result in that enum type converter being used for options and positional parameters with that enum type
- that the custom enum type converter will NOT be used if a custom
ITypeConverteris registered for that enum type - a custom enum type converter falling back to the default enum type converter
- setting
CommandLine::setCaseInsensitiveEnumValuesAllowedtotrueprior to parsing will result in the custom enum type converter being called with valuetrue - not calling
CommandLine::setCaseInsensitiveEnumValuesAllowedprior to parsing will result in the custom enum type converter being called with valuefalse - throwing a TypeConversionException from the registered custom enum type converter will result in a
ParameterExceptionwith a user-friendly message fromCommandLine::parseArgs - registering a
nullcustom enum type converter is rejected immediately with a NullPointerException (not silently accepted, causing problems during parsing) - calling
CommandLine::registerEnumConverterwill register the custom enum type converter for that command and all its subcommands and sub-subcommands
(most tests are here: src/test/java/picocli)
|
Thank you for considering this.
As I explained in #1804, unfortunately I do not have time to try to work with a build system that does not behave properly with the latest Java version. If the build configuration allowed me to clone the repository and then successfully run existing tests by simply invoking I do not have the time to try to fix the build system or to downgrade my toolchain to try to coax the build system into working. Thus I will not be providing any tests for this pull request unless the build system is fixed. I'm sorry. |
| String name = enumConstant.name(); | ||
| if (value.equals(str) || value.equals(name) || caseInsensitiveEnumValuesAllowed && (value.equalsIgnoreCase(str) || value.equalsIgnoreCase(name))) { | ||
| return enumConstant; | ||
| } } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just noticed this formatting oddity and thought I had made a typo, but then I saw it was in the original code, so I'll leave it as-is for the moment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed it too in the original code. Looks like a newline was accidentally deleted. It was not intentional, please fix in the PR.
|
@garretwilson The project now builds correctly on Java 24 and Gradle 8.14. The Github CI build now also includes Java 24. |
I pulled the latest from upstream and then tried Did you want to look into that failing test? |
|
Also note that importing this project into both Eclipse and VS Code with Java support raised the exact same error. I'll see if I can work around that, but it's something else you probably should look into. |
|
Unfortunately, even adding a JUnit 4 It's at this point I realize again that going in circles is going to waste the whole morning, so I'm stopping this for today. Could you make sure that |
|
Strange, all tests pass with Java 24 on my machine, and also on Github, both in the main branch and on your branch (macos build failures for Java 9 are ignored). The GitHub tests cover a wide range of Java versions and operating systems, I wonder what is different about your environment. The two failing tests for |
|
I am guessing that the failing tests were because the usage help message had ANSI escape codes in the output in your environment. I fixed the tests to ensure that the comparison is without the escape codes regardless of the environment. |
|
Good news — I am now able to run |
|
FYI, using |
|
@remkop I've added the unit tests you've requested. As I mentioned in issue #1804, I started with tests an LLM generated, and I haven't looked at the tests super closely. However I did glance over them just now and tweaked them a little. It's amazing, after I got the LLM aligned with what I was looking for (e.g. specifying a Java 8 build, JUnit 4, consistency with existing picocli tests, etc) how little tweaking I needed to do. Here are some example:
I haven't updated any documentation; I'll have to do that on another day when I can find another few minutes free. In the meantime please take a look at the tests and tell me if they're OK. Please also respond to the earlier question I had in the main ticket about how you want to test a "user-friendly error message". Thanks and have a great weekend. |
I took a look at the docs, and section "4.2. Custom Type Converters" is the one about converters, so I'm thinking right before section Take a look and let me know what you think. I think these docs are the last thing to finalize for this PR. |
Pluggable enum conversion facility for #1804 .