use of joptsimple.OptionParser in project jopt-simple by jopt-simple.
the class LongOptionsTest method acceptsLongOptions.
@Test
public void acceptsLongOptions() {
OptionParser parser = new OptionParser();
parser.accepts("flag");
parser.accepts("verbose");
OptionSet options = parser.parse("--flag");
assertTrue(options.has("flag"));
assertFalse(options.has("verbose"));
}
use of joptsimple.OptionParser in project jopt-simple by jopt-simple.
the class LongOptionsWithArgumentsTest method supportsLongOptionsWithEmptyArguments.
@Test
public void supportsLongOptionsWithEmptyArguments() {
OptionParser parser = new OptionParser();
parser.accepts("verbose");
parser.accepts("brief");
parser.accepts("add");
parser.accepts("append");
parser.accepts("delete").withRequiredArg();
parser.accepts("create").withRequiredArg();
parser.accepts("file").withRequiredArg();
OptionSet options = parser.parse("--delete", "", "--add");
assertTrue(options.has("delete"));
assertTrue(options.hasArgument("delete"));
assertEquals("", options.valueOf("delete"));
assertTrue(options.has("add"));
options = parser.parse("--delete=", "--add");
assertTrue(options.has("delete"));
assertTrue(options.hasArgument("delete"));
assertEquals("", options.valueOf("delete"));
assertTrue(options.has("add"));
}
use of joptsimple.OptionParser in project jopt-simple by jopt-simple.
the class LongOptionsWithArgumentsTest method supportsLongOptionsWithArgumentsAndAbbreviations.
@Test
public void supportsLongOptionsWithArgumentsAndAbbreviations() {
OptionParser parser = new OptionParser();
parser.accepts("flag");
parser.accepts("count").withRequiredArg();
parser.accepts("level").withOptionalArg();
OptionSet options = parser.parse("-flag", "--co", "3", "--lev");
assertTrue(options.has("flag"));
assertTrue(options.has("count"));
assertTrue(options.hasArgument("count"));
assertEquals("3", options.valueOf("count"));
assertEquals(singletonList("3"), options.valuesOf("count"));
assertTrue(options.has("level"));
assertFalse(options.hasArgument("level"));
assertNull(options.valueOf("level"));
assertEquals(emptyList(), options.valuesOf("level"));
}
use of joptsimple.OptionParser in project jopt-simple by jopt-simple.
the class MultipleDelimitedArgumentsTest method supportsMultipleDelimitedArguments.
@Test
public void supportsMultipleDelimitedArguments() {
OptionParser parser = new OptionParser();
OptionSpec<File> path = parser.accepts("path").withRequiredArg().ofType(File.class).withValuesSeparatedBy(pathSeparatorChar);
OptionSet options = parser.parse("--path", Stream.of("/tmp", "/var", "/opt").collect(joining(pathSeparator)));
assertTrue(options.has(path));
assertTrue(options.hasArgument(path));
assertEquals(asList(new File("/tmp"), new File("/var"), new File("/opt")), options.valuesOf(path));
}
use of joptsimple.OptionParser in project jopt-simple by jopt-simple.
the class OptionArgumentConverterTest method usesConvertersOnOptionArgumentsWhenTold.
@Test
public void usesConvertersOnOptionArgumentsWhenTold() {
OptionParser parser = new OptionParser();
parser.accepts("birthdate").withRequiredArg().withValuesConvertedBy(datePattern("MM/dd/yy"));
parser.accepts("ssn").withRequiredArg().withValuesConvertedBy(regex("\\d{3}-\\d{2}-\\d{4}"));
OptionSet options = parser.parse("--birthdate", "02/24/05", "--ssn", "123-45-6789");
assertEquals(new LocalDate(2005, 2, 24).toDate(), options.valueOf("birthdate"));
assertEquals("123-45-6789", options.valueOf("ssn"));
}
Aggregations