Added help message to display

This commit is contained in:
Isaac Parenteau
2018-09-13 19:38:24 -05:00
parent bbb3c08ba9
commit 696107ec8f
2 changed files with 102 additions and 21 deletions

View File

@@ -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();
}
}