If you are building a command-line app and you want to pass multiple values in a single option, there is a built-it support for that in args4j.
The only thing you have to do is to extend org.kohsuke.args4j.spi.DelimitedOptionHandler
, passing the delimiter (","
in the example below) and the single-value option handler (IntOptionHandler
).
public class MultiIntOptionHandler extends DelimitedOptionHandler<Integer> { public MultiIntOptionHandler(CmdLineParser parser, OptionDef option, Setter<? super Integer> setter) { super(parser, option, setter, ",", new IntOptionHandler(parser, option, setter)); } }
The usage is straightforward:
@Option(name = "-e", aliases = "--elapse", usage = "elapses in", handler = MultiIntOptionHandler.class) private List<Integer> elapsesIn = new ArrayList<>();