Unless I've missed something it doesn't seem to be possible to implement multi-option with arity like in jcommander, is that correct ?
so for example i have an option that take two strings, and I want to be able to use that option multiple times:
-val foo bar -val zaz zoz
@ymenager Sorry for my late reply.
The use case you mention should already work like you describe.
See this unit test (and the two preceding tests): https://github.com/remkop/picocli/blob/master/src/test/java/picocli/CommandLineArityTest.java#L622
If I missed something, can you provide a program (or a failing test) that reproduces the problem?
Ah, I see... my test was wrong I thought i had to use a list of lists in that scenario.. all good then :)
Glad to hear that!
Please use specific commit link for CommmandLineArityTest#L622. This makes finding this a lot easier.
The test specifies double[] doubleOptions. What if I prefer double[][] doubleOptions, or in my use case String[][]? Following the initial comment, I would like to have something like
{
{"foo", "bar"},
{"zaz", "zoz"}
}
This sounds a bit like #358 repeating argument groups. However, an argument group would probably be a separate class with annotations for the elements of the group. Something like
class Pair {
@Parameter(index = “0” arity = “1”)
double first;
@Parameter(index = “1” arity = “1”)
double second;
}
Then the application would look something like:
class App {
@Option(names = “-v”)
boolean verbose;
@Option(names = “--pair”)
Pair[] pairs;
}
As it stands, picocli can only gather the value pairs in a 1-dimensional array.
If you want nested arrays you’ll have to convert this array into a multi-dimensional array in the application.
Separate classes with annotations seems like a very reasonable solution.
cc @nthistle
It may take a while before I can get to #358 though.
We will pass each group as comma separated String for now and can break the command line interface without worries once #358 is merged, so that solution works for us. Btw, picocli has made my command line parsing life in Java so much better.
Most helpful comment
This sounds a bit like #358 repeating argument groups. However, an argument group would probably be a separate class with annotations for the elements of the group. Something like
Then the application would look something like:
As it stands, picocli can only gather the value pairs in a 1-dimensional array.
If you want nested arrays you’ll have to convert this array into a multi-dimensional array in the application.