args4j
args4j copied to clipboard
Missing multiValued attribute in @Option
After updating to the newest args4j version I do have compile errors because of the removed "multiValued" attribute. I found the commit message which told, that it was removed because it would make no sense to have multi-value settings.
What about this case (which is simlar to mine):
@Option(name = "-in", multiValued = true, required = true)
private List<File> inFiles;
where I do support multiple ouccrences of -in (e.g. FooMain -in fileA.txt -in fileB.txt -in fileC.txt). How can this be done with the new release of args4j?
We're also using multiValued. If the option doesn't hurt, i think you should left it to the user whether it makes sense or not.
Hello, I was using the multiValues attribute, too.
I guess I could use just a single value argument and pass multiple values separated by a comma. In example, instead: -in fileA -in fileB -in fileC You could use: -in fileA,fileB,fileC
Of course you need to take into account if the file have a comma in the name but you can just force your users to escape the comma: -in file,A,fileB,fileC
Is there an alternative to using multiValued in there, or a reason it was taken out? Is there interest a contribution to add it back in?
Who knows if anyone here cares or not still, but seems like multivalue just works if you use a list... see here -> multivalued test for more info.
@jaredpetker
Thanks for the info, I've been looking for that.
Finally figured out how to do this. It should really be added to the main example, considering how useful it is, (and considering I had to do work to figure out how to do it) but here's the solution:
@Option(name = "-in", handler=StringArrayOptionHandler.class")
private List<String> inFiles;
Then you can use, -in <item1> <item2>
+1 for adding this to the doc. Thanks!
I had to pass
-in "United States" "United Kingdom"
Found that the handler is breaking it into four words : [United, States, United, Kingdom]
but I expected two words : [United States, United Kingdom]
Warning:Stay away from this if your argument values consists of multiwords with spaces.
@thammegowda note that the Javadoc for StringArrayOptionHandler
indicates this is expected behavior:
All of [these examples] result in a single string array that contains three tokens:
banan
,hruska
, andjablko
.
If you need proper quoting support it might be better to use the default behavior and use the flag repeatedly, i.e.:
-in "United States" -in "United Kingdom"
Hi all,
I found maybe a bug when I configure an option like that:
@Option(name = "-in", handler=StringArrayOptionHandler.class")
private List<String> inFiles;
When I do this call (no operands):
myApp -in
There are no exceptions thrown to tell that there are no operands.
StringArrayOptionHandler.parseArguments
will return 0
and the test in CmdLineParser.getParameter(int )
does not fail like it does with a simple string option
There are no exceptions thrown to tell that there are no operands. StringArrayOptionHandler.parseArguments will return 0
I would consider this the correct behaviour, since an empty list looks totally fine to me