Multiple args with arg4j

I have a parameter that I need to parse from the command line. I use arg4j version 2.0.23 for this. I need to analyze the path parameter, and one or more paths can be specified on the command line. Therefore, I need to parse several parameters. Here is how I find:

private List<String> list = new ArrayList<String>();

@Option(name = "-p", required = true)
public void addPath(String arg) {list.add(arg);}  

It is working fine. But I want to know if this is right or is there a better way? I googled that in version 2.0.13 there was a multipleValue parameter in @Option, but now it has disappeared.

+4
source share
1 answer

Try:

import org.kohsuke.args4j.spi.StringArrayOptionHandler;

@Option(name = "-p", handler = StringArrayOptionHandler.class, required = true)
private List<String> list;

which should allow

-p arg1 arg2 ...
+6
source

Source: https://habr.com/ru/post/1541539/


All Articles