jcommander
jcommander copied to clipboard
Hyphen inside an argument with variable arity can't be parsed
Basically, if you have argument with variable arity and hyphen inside the argument: "-argument1 foo - bar -argument2...", exception is thrown. Works fine if arity would be set to 3 in this case.
package org.saulis;
import com.beust.jcommander.JCommander;
import com.beust.jcommander.Parameter;
import org.junit.Test;
import java.util.List;
public class HyphenTest {
public class Arguments {
@Parameter(required = true, names = "-argument1", variableArity = true)
public List<String> argument1;
}
@Test
public void hyphenIsParsed() {
Arguments arguments = new Arguments();
new JCommander(arguments, "-argument1", "foo", "-", "bar");
}
}
Throws:
com.beust.jcommander.ParameterException: Unknown option: -
at com.beust.jcommander.JCommander.parseValues(JCommander.java:723)
at com.beust.jcommander.JCommander.parse(JCommander.java:275)
at com.beust.jcommander.JCommander.parse(JCommander.java:258)
at com.beust.jcommander.JCommander.<init>(JCommander.java:203)
at org.saulis.HyphenTest.hyphenIsParsed(HyphenTest.java:21)
@cbeust what do you say, is this an error?