jcommander icon indicating copy to clipboard operation
jcommander copied to clipboard

Hyphen inside an argument with variable arity can't be parsed

Open Saulis opened this issue 10 years ago • 1 comments

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)

Saulis avatar Dec 22 '14 20:12 Saulis

@cbeust what do you say, is this an error?

jeremysolarz avatar Jan 15 '17 15:01 jeremysolarz