cbeust / jcommander

Command line parsing framework for Java

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add possibility for list -> object

StaffanArvidsson opened this issue · comments

I would like to have the possibility to go from a list of strings as input to an object, i.e. have an interface similar to IStringConverter that instead take a list of Strings or possibly an array. This would solve issues were a complex type needs to be specified, or one that has dynamic parameters depending on the concrete implementation. For example I take input files that can be of several formats, so I'd like to get a syntax like:
--input-file CSV delimiter:, header:true
But if I instead have a JSON input, the delimiter and header arguments are not possible. I've solved this currently by only taking a List of variable arity and then add conversion into the final object afterward. But that makes the flow in the code somewhat odd and easier to miss doing the conversion. So an interface:

public interface IStringListConverter {
T convert(List values);
}

Or is there any current approach that would solve this in a better way?