我正在使用jcommander 1.72来处理REPL中的命令(不直接从命令行)。我有一个可以选择取值的参数;如果提供了值,则设置该值。如果未提供任何值,则打印当前值。例如:
> myCmd --foo 5
set foo = 5
> myCmd --foo
current value of foo = 5
我尝试过:
@Parameter(names = {"-f", "--foo"}, variableArity=true)
List<String> foo = new ArrayList<>()
但是我得到这个错误:
com.beust.jcommander.ParameterException: Expected a value after parameter --foo
at com.beust.jcommander.JCommander.processFixedArity(JCommander.java:886)
at com.beust.jcommander.JCommander.processVariableArity(JCommander.java:859)
at com.beust.jcommander.JCommander.parseValues(JCommander.java:705)
at com.beust.jcommander.JCommander.parse(JCommander.java:340)
at com.beust.jcommander.JCommander.parseValues(JCommander.java:787)
at com.beust.jcommander.JCommander.parse(JCommander.java:340)
at com.beust.jcommander.JCommander.parse(JCommander.java:319)
...
如何在jcommander中完成此操作?