Search in sources :

Example 76 with OptionSet

use of joptsimple.OptionSet in project PayFile by mikehearn.

the class CLI method main.

public static void main(String[] args) throws Exception {
    BriefLogFormatter.init();
    //Logger.getLogger("").setLevel(Level.OFF);
    // allow client to choose another network for testing by passing through an argument.
    OptionParser parser = new OptionParser();
    parser.accepts("network").withRequiredArg().withValuesConvertedBy(regex("(mainnet)|(testnet)|(regtest)")).defaultsTo("mainnet");
    parser.accepts("server").withRequiredArg().required();
    parser.accepts("help").forHelp();
    parser.formatHelpWith(new BuiltinHelpFormatter(120, 10));
    OptionSet options;
    try {
        options = parser.parse(args);
    } catch (OptionException e) {
        System.err.println(e.getMessage());
        System.err.println("");
        parser.printHelpOn(System.err);
        return;
    }
    if (options.has("help")) {
        parser.printHelpOn(System.out);
        return;
    }
    if (options.valueOf("network").equals(("testnet"))) {
        params = TestNet3Params.get();
        filePrefix = "testnet-";
    } else if (options.valueOf("network").equals(("mainnet"))) {
        params = MainNetParams.get();
        filePrefix = "";
    } else if (options.valueOf("network").equals(("regtest"))) {
        params = RegTestParams.get();
        filePrefix = "regtest-";
    }
    String server = options.valueOf("server").toString();
    System.out.println("Connecting to " + server);
    Socket socket = new Socket(server, 18754);
    final CLI cli = new CLI(socket);
    ShellFactory.createConsoleShell(server, "PayFile", cli).commandLoop();
    cli.shutdown();
}
Also used : BuiltinHelpFormatter(joptsimple.BuiltinHelpFormatter) OptionException(joptsimple.OptionException) OptionSet(joptsimple.OptionSet) OptionParser(joptsimple.OptionParser) Socket(java.net.Socket)

Example 77 with OptionSet

use of joptsimple.OptionSet in project spring-boot by spring-projects.

the class OptionHandler method run.

public final ExitStatus run(String... args) throws Exception {
    String[] argsToUse = args.clone();
    for (int i = 0; i < argsToUse.length; i++) {
        if ("-cp".equals(argsToUse[i])) {
            argsToUse[i] = "--cp";
        }
    }
    OptionSet options = getParser().parse(argsToUse);
    return run(options);
}
Also used : OptionSet(joptsimple.OptionSet)

Example 78 with OptionSet

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

the class JOptCommandLinePropertySourceTests method withRequiredArg_andArgIsPresent.

@Test
public void withRequiredArg_andArgIsPresent() {
    OptionParser parser = new OptionParser();
    parser.accepts("foo").withRequiredArg();
    OptionSet options = parser.parse("--foo=bar");
    PropertySource<?> ps = new JOptCommandLinePropertySource(options);
    assertThat((String) ps.getProperty("foo"), equalTo("bar"));
}
Also used : OptionSet(joptsimple.OptionSet) OptionParser(joptsimple.OptionParser) Test(org.junit.Test)

Example 79 with OptionSet

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

the class JOptCommandLinePropertySourceTests method withRequiredArg_andMultipleArgsPresent_usingRepeatedOption.

@Test
public void withRequiredArg_andMultipleArgsPresent_usingRepeatedOption() {
    OptionParser parser = new OptionParser();
    parser.accepts("foo").withRequiredArg().withValuesSeparatedBy(',');
    OptionSet options = parser.parse("--foo=bar", "--foo=baz", "--foo=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 80 with OptionSet

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

the class JOptCommandLinePropertySourceTests method withOptionalArg_andArgIsMissing.

@Test
public void withOptionalArg_andArgIsMissing() {
    OptionParser parser = new OptionParser();
    parser.accepts("foo").withOptionalArg();
    OptionSet options = parser.parse("--foo");
    PropertySource<?> ps = new JOptCommandLinePropertySource(options);
    assertThat(ps.containsProperty("foo"), is(true));
    assertThat((String) ps.getProperty("foo"), equalTo(""));
}
Also used : OptionSet(joptsimple.OptionSet) OptionParser(joptsimple.OptionParser) Test(org.junit.Test)

Aggregations

OptionSet (joptsimple.OptionSet)121 OptionParser (joptsimple.OptionParser)93 File (java.io.File)40 OptionException (joptsimple.OptionException)22 IOException (java.io.IOException)20 List (java.util.List)16 Cluster (voldemort.cluster.Cluster)13 ArrayList (java.util.ArrayList)12 Test (org.junit.Test)12 StoreDefinition (voldemort.store.StoreDefinition)12 ClusterMapper (voldemort.xml.ClusterMapper)10 StoreDefinitionsMapper (voldemort.xml.StoreDefinitionsMapper)9 FileNotFoundException (java.io.FileNotFoundException)6 VoldemortException (voldemort.VoldemortException)6 BufferedReader (java.io.BufferedReader)5 Properties (java.util.Properties)5 OptionSpec (joptsimple.OptionSpec)5 Node (voldemort.cluster.Node)5 ByteArray (voldemort.utils.ByteArray)5 Closer (com.google.common.io.Closer)4