Added help message to display
This commit is contained in:
@@ -11,33 +11,40 @@ import net.locusworks.argparser.annotations.Parameter;
|
||||
import net.locusworks.argparser.converters.IntegerConverter;
|
||||
|
||||
public class ArgParserTest {
|
||||
|
||||
|
||||
public static class Args {
|
||||
@Parameter(names="position2", positional=true, order=2)
|
||||
public String position2;
|
||||
|
||||
|
||||
@Parameter(names="position1", positional=true, order=1)
|
||||
public String position1;
|
||||
|
||||
@Parameter(names="-list", variableArity=true)
|
||||
|
||||
@Parameter(names= {"-l", "--list"}, description="List of values", variableArity=true)
|
||||
public List<String> values;
|
||||
|
||||
@Parameter(names="-count", converter=IntegerConverter.class)
|
||||
public int count;
|
||||
|
||||
|
||||
@Parameter(names="-count", converter=IntegerConverter.class, required=true)
|
||||
public Integer count;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void testArgParser() {
|
||||
String[] args = new String[] {"Hello", "World", "-list", "hell", "world", "-count", "1"};
|
||||
|
||||
String[] args = new String[] {"Hello", "World", "--list", "hell", "world", "-count", "1"};
|
||||
|
||||
Args arg = ArgParser.newBuilder().withArgClass(Args.class).parse(args);
|
||||
|
||||
|
||||
assertTrue(arg.position2.equals(args[0]));
|
||||
assertTrue(arg.position1.equals(args[1]));
|
||||
assertTrue(arg.values.size() == 2);
|
||||
assertTrue(arg.count == 1);
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testNoRequired() {
|
||||
String[] args = new String[] {"Hello", "World", "--list", "hell", "world"};
|
||||
|
||||
ArgParser.newBuilder().withArgClass(Args.class).parse(args);
|
||||
fail();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user