Search in sources :

Example 56 with OptionParser

use of joptsimple.OptionParser in project spring-framework by spring-projects.

the class JOptCommandLinePropertySourceTests method withDefaultNonOptionArgsNameAndNonOptionArgsPresent.

@Test
public void withDefaultNonOptionArgsNameAndNonOptionArgsPresent() {
    OptionParser parser = new OptionParser();
    parser.accepts("o1").withRequiredArg();
    parser.accepts("o2");
    OptionSet optionSet = parser.parse("--o1=v1", "noa1", "--o2", "noa2");
    PropertySource<?> ps = new JOptCommandLinePropertySource(optionSet);
    assertThat(ps.containsProperty("nonOptionArgs"), is(true));
    assertThat(ps.containsProperty("o1"), is(true));
    assertThat(ps.containsProperty("o2"), is(true));
    String nonOptionArgs = (String) ps.getProperty("nonOptionArgs");
    assertThat(nonOptionArgs, equalTo("noa1,noa2"));
}
Also used : OptionSet(joptsimple.OptionSet) OptionParser(joptsimple.OptionParser) Test(org.junit.Test)

Example 57 with OptionParser

use of joptsimple.OptionParser in project spring-framework by spring-projects.

the class JOptCommandLinePropertySourceTests method withRequiredArg_andMultipleArgsPresent_usingDelimiter.

@Test
public void withRequiredArg_andMultipleArgsPresent_usingDelimiter() {
    OptionParser parser = new OptionParser();
    parser.accepts("foo").withRequiredArg().withValuesSeparatedBy(',');
    OptionSet options = parser.parse("--foo=bar,baz,biz");
    CommandLinePropertySource<?> ps = new JOptCommandLinePropertySource(options);
    assertEquals(Arrays.asList("bar", "baz", "biz"), ps.getOptionValues("foo"));
    assertThat(ps.getProperty("foo"), equalTo("bar,baz,biz"));
}
Also used : OptionSet(joptsimple.OptionSet) OptionParser(joptsimple.OptionParser) Test(org.junit.Test)

Example 58 with OptionParser

use of joptsimple.OptionParser in project spring-framework by spring-projects.

the class JOptCommandLinePropertySourceTests method withRequiredArg_ofTypeEnum.

@Test
public void withRequiredArg_ofTypeEnum() {
    OptionParser parser = new OptionParser();
    parser.accepts("o1").withRequiredArg().ofType(OptionEnum.class);
    OptionSet options = parser.parse("--o1=VAL_1");
    PropertySource<?> ps = new JOptCommandLinePropertySource(options);
    assertThat(ps.getProperty("o1"), equalTo("VAL_1"));
}
Also used : OptionSet(joptsimple.OptionSet) OptionParser(joptsimple.OptionParser) Test(org.junit.Test)

Example 59 with OptionParser

use of joptsimple.OptionParser in project spring-framework by spring-projects.

the class JOptCommandLinePropertySourceTests method withMissingOption.

@Test
public void withMissingOption() {
    OptionParser parser = new OptionParser();
    parser.accepts("foo").withRequiredArg().withValuesSeparatedBy(',');
    // <-- no options whatsoever
    OptionSet options = parser.parse();
    PropertySource<?> ps = new JOptCommandLinePropertySource(options);
    assertThat(ps.getProperty("foo"), nullValue());
}
Also used : OptionSet(joptsimple.OptionSet) OptionParser(joptsimple.OptionParser) Test(org.junit.Test)

Example 60 with OptionParser

use of joptsimple.OptionParser in project spring-framework by spring-projects.

the class JOptCommandLinePropertySourceTests method withDefaultNonOptionArgsNameAndNoNonOptionArgsPresent.

@Test
public void withDefaultNonOptionArgsNameAndNoNonOptionArgsPresent() {
    OptionParser parser = new OptionParser();
    parser.acceptsAll(Arrays.asList("o1", "option1")).withRequiredArg();
    parser.accepts("o2");
    OptionSet optionSet = parser.parse("--o1=v1", "--o2");
    EnumerablePropertySource<?> ps = new JOptCommandLinePropertySource(optionSet);
    assertThat(ps.containsProperty("nonOptionArgs"), is(false));
    assertThat(ps.containsProperty("o1"), is(true));
    assertThat(ps.containsProperty("o2"), is(true));
    assertThat(ps.containsProperty("nonOptionArgs"), is(false));
    assertThat(ps.getProperty("nonOptionArgs"), nullValue());
    assertThat(ps.getPropertyNames().length, is(2));
}
Also used : OptionSet(joptsimple.OptionSet) OptionParser(joptsimple.OptionParser) Test(org.junit.Test)

Aggregations

OptionParser (joptsimple.OptionParser)121 OptionSet (joptsimple.OptionSet)94 File (java.io.File)35 OptionException (joptsimple.OptionException)16 IOException (java.io.IOException)15 List (java.util.List)13 Test (org.junit.Test)13 ArrayList (java.util.ArrayList)11 Cluster (voldemort.cluster.Cluster)8 FileNotFoundException (java.io.FileNotFoundException)6 StoreDefinition (voldemort.store.StoreDefinition)6 Closer (com.google.common.io.Closer)5 BufferedReader (java.io.BufferedReader)5 Properties (java.util.Properties)5 OptionSpec (joptsimple.OptionSpec)5 Node (voldemort.cluster.Node)5 ByteArray (voldemort.utils.ByteArray)5 ClusterMapper (voldemort.xml.ClusterMapper)5 MongoClientURI (com.mongodb.MongoClientURI)4 FileReader (java.io.FileReader)4