Search in sources :

Example 36 with OptionParser

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"));
}
Also used : OptionSet(joptsimple.OptionSet) OptionParser(joptsimple.OptionParser) Test(org.junit.Test)

Example 37 with OptionParser

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"));
}
Also used : OptionSet(joptsimple.OptionSet) OptionParser(joptsimple.OptionParser) Test(org.junit.Test)

Example 38 with OptionParser

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"));
}
Also used : OptionSet(joptsimple.OptionSet) OptionParser(joptsimple.OptionParser) Test(org.junit.Test)

Example 39 with OptionParser

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));
}
Also used : OptionSet(joptsimple.OptionSet) OptionParser(joptsimple.OptionParser) File(java.io.File) Test(org.junit.Test)

Example 40 with OptionParser

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"));
}
Also used : OptionSet(joptsimple.OptionSet) OptionParser(joptsimple.OptionParser) LocalDate(org.joda.time.LocalDate) Test(org.junit.Test)

Aggregations

OptionParser (joptsimple.OptionParser)199 OptionSet (joptsimple.OptionSet)151 File (java.io.File)58 IOException (java.io.IOException)29 Test (org.junit.Test)28 OptionException (joptsimple.OptionException)25 ArrayList (java.util.ArrayList)21 Properties (java.util.Properties)16 List (java.util.List)15 OptionSpec (joptsimple.OptionSpec)14 Test (org.junit.jupiter.api.Test)12 VerifiableProperties (com.github.ambry.config.VerifiableProperties)11 FileNotFoundException (java.io.FileNotFoundException)9 BufferedReader (java.io.BufferedReader)8 ArgumentAcceptingOptionSpec (joptsimple.ArgumentAcceptingOptionSpec)8 FileReader (java.io.FileReader)7 OptionSpecBuilder (joptsimple.OptionSpecBuilder)7 Closer (com.google.common.io.Closer)6 Cluster (voldemort.cluster.Cluster)6 StoreDefinition (voldemort.store.StoreDefinition)6