-
Hi, We are evaluating to move to 'picocli' for a re-write of one command line applications. However, we have noticed an issue with POSIX short options we are heavily using. Coming from 'getopt' following options have all the same value '2' ... '-v=2', '-v2' and '-v 2'. With 'picocli', only '-v=2' and '-v2' produce the expected value '2'. '-v 2' however produces ' 2', which leads to a 'NumberFormatException' in the default integer converter. Now, question is ... Is this a feature or a bug? It is easy to fix by trimming the value string when getting it from the 'args' stack in 'CommandLine::applyValueToSingleValuedField'. Kind regards |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments
-
That would be a bug but I believe I have tests that show different behaviour. |
Beta Was this translation helpful? Give feedback.
-
If you execute the attached 'DemoOptionsHandlerTest', you get ... Invalid value for option '--verbosity': ' 3' is not an int |
Beta Was this translation helpful? Give feedback.
-
Thank you! Note that // currently: passing an array with one element
DemoOptionsHandler.parse(new String[] { "-v 3" }); This results in the I believe your intention is to test this: // should: pass an array with two elements
DemoOptionsHandler.parse(new String[] { "-v", "3" }); That would be closer to what happens when the user invokes your command on the command line like this:
The shell will tokenize the input and the |
Beta Was this translation helpful? Give feedback.
-
Ah, yes, you are right. Good catch. Thx |
Beta Was this translation helpful? Give feedback.
Thank you! Note that
DemoOptionsHandlerTest
incorrectly tests this:This results in the
-v
option getting the value of the string" 3"
(space followed by the character '3')I believe your intention is to test this:
That would be closer to what happens when the user invokes your command on the command line like this:
The shell will tokenize the input and the
main
method of your application will receive an array with 2 elements, "-v" and "3".I hope this clarifies.