Search in sources :

Example 11 with OptionException

use of joptsimple.OptionException in project bitsquare by bitsquare.

the class SeedNodeMain method main.

public static void main(String[] args) throws Exception {
    final ThreadFactory threadFactory = new ThreadFactoryBuilder().setNameFormat("SeedNodeMain").setDaemon(true).build();
    UserThread.setExecutor(Executors.newSingleThreadExecutor(threadFactory));
    // We don't want to do the full argument parsing here as that might easily change in update versions
    // So we only handle the absolute minimum which is APP_NAME, APP_DATA_DIR_KEY and USER_DATA_DIR
    BitsquareEnvironment.setDefaultAppName("Bitsquare_seednode");
    OptionParser parser = new OptionParser();
    parser.allowsUnrecognizedOptions();
    parser.accepts(AppOptionKeys.USER_DATA_DIR_KEY, description("User data directory", DEFAULT_USER_DATA_DIR)).withRequiredArg();
    parser.accepts(AppOptionKeys.APP_NAME_KEY, description("Application name", DEFAULT_APP_NAME)).withRequiredArg();
    OptionSet options;
    try {
        options = parser.parse(args);
    } catch (OptionException ex) {
        System.out.println("error: " + ex.getMessage());
        System.out.println();
        parser.printHelpOn(System.out);
        System.exit(EXIT_FAILURE);
        return;
    }
    BitsquareEnvironment bitsquareEnvironment = new BitsquareEnvironment(options);
    // need to call that before BitsquareAppMain().execute(args)
    BitsquareExecutable.initAppDir(bitsquareEnvironment.getProperty(AppOptionKeys.APP_DATA_DIR_KEY));
    // For some reason the JavaFX launch process results in us losing the thread context class loader: reset it.
    // In order to work around a bug in JavaFX 8u25 and below, you must include the following code as the first line of your realMain method:
    Thread.currentThread().setContextClassLoader(SeedNodeMain.class.getClassLoader());
    new SeedNodeMain().execute(args);
}
Also used : ThreadFactory(java.util.concurrent.ThreadFactory) ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) OptionException(joptsimple.OptionException) BitsquareEnvironment(io.bitsquare.app.BitsquareEnvironment) OptionSet(joptsimple.OptionSet) OptionParser(joptsimple.OptionParser)

Example 12 with OptionException

use of joptsimple.OptionException in project bitsquare by bitsquare.

the class BitsquareAppMain method main.

public static void main(String[] args) throws Exception {
    // We don't want to do the full argument parsing here as that might easily change in update versions
    // So we only handle the absolute minimum which is APP_NAME, APP_DATA_DIR_KEY and USER_DATA_DIR
    OptionParser parser = new OptionParser();
    parser.allowsUnrecognizedOptions();
    parser.accepts(AppOptionKeys.USER_DATA_DIR_KEY, description("User data directory", DEFAULT_USER_DATA_DIR)).withRequiredArg();
    parser.accepts(AppOptionKeys.APP_NAME_KEY, description("Application name", DEFAULT_APP_NAME)).withRequiredArg();
    OptionSet options;
    try {
        options = parser.parse(args);
    } catch (OptionException ex) {
        System.out.println("error: " + ex.getMessage());
        System.out.println();
        parser.printHelpOn(System.out);
        System.exit(EXIT_FAILURE);
        return;
    }
    BitsquareEnvironment bitsquareEnvironment = new BitsquareEnvironment(options);
    // need to call that before BitsquareAppMain().execute(args)
    BitsquareExecutable.initAppDir(bitsquareEnvironment.getProperty(AppOptionKeys.APP_DATA_DIR_KEY));
    // For some reason the JavaFX launch process results in us losing the thread context class loader: reset it.
    // In order to work around a bug in JavaFX 8u25 and below, you must include the following code as the first line of your realMain method:
    Thread.currentThread().setContextClassLoader(BitsquareAppMain.class.getClassLoader());
    new BitsquareAppMain().execute(args);
}
Also used : OptionException(joptsimple.OptionException) OptionSet(joptsimple.OptionSet) OptionParser(joptsimple.OptionParser)

Example 13 with OptionException

use of joptsimple.OptionException in project elasticsearch by elastic.

the class Command method main.

/** Parses options for this command from args and executes it. */
public final int main(String[] args, Terminal terminal) throws Exception {
    if (addShutdownHook()) {
        shutdownHookThread.set(new Thread(() -> {
            try {
                this.close();
            } catch (final IOException e) {
                try (StringWriter sw = new StringWriter();
                    PrintWriter pw = new PrintWriter(sw)) {
                    e.printStackTrace(pw);
                    terminal.println(sw.toString());
                } catch (final IOException impossible) {
                    // say that an exception here is impossible
                    throw new AssertionError(impossible);
                }
            }
        }));
        Runtime.getRuntime().addShutdownHook(shutdownHookThread.get());
    }
    // initialize default for es.logger.level because we will not read the log4j2.properties
    final String loggerLevel = System.getProperty("es.logger.level", Level.INFO.name());
    final Settings settings = Settings.builder().put("logger.level", loggerLevel).build();
    LogConfigurator.configureWithoutConfig(settings);
    try {
        mainWithoutErrorHandling(args, terminal);
    } catch (OptionException e) {
        printHelp(terminal);
        terminal.println(Terminal.Verbosity.SILENT, "ERROR: " + e.getMessage());
        return ExitCodes.USAGE;
    } catch (UserException e) {
        if (e.exitCode == ExitCodes.USAGE) {
            printHelp(terminal);
        }
        terminal.println(Terminal.Verbosity.SILENT, "ERROR: " + e.getMessage());
        return e.exitCode;
    }
    return ExitCodes.OK;
}
Also used : StringWriter(java.io.StringWriter) OptionException(joptsimple.OptionException) IOException(java.io.IOException) Settings(org.elasticsearch.common.settings.Settings) PrintWriter(java.io.PrintWriter)

Example 14 with OptionException

use of joptsimple.OptionException in project elasticsearch by elastic.

the class CommandTests method testVerbositySilentAndVerbose.

public void testVerbositySilentAndVerbose() throws Exception {
    MockTerminal terminal = new MockTerminal();
    NoopCommand command = new NoopCommand();
    String[] args = { "-v", "-s" };
    OptionException e = expectThrows(OptionException.class, () -> {
        command.mainWithoutErrorHandling(args, terminal);
    });
    assertTrue(e.getMessage(), e.getMessage().contains("Option(s) [v/verbose] are unavailable given other options on the command line"));
}
Also used : OptionException(joptsimple.OptionException)

Example 15 with OptionException

use of joptsimple.OptionException in project PayFile by mikehearn.

the class Main method main.

public static void main(String[] args) throws Exception {
    // 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("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-";
    }
    launch(args);
}
Also used : BuiltinHelpFormatter(joptsimple.BuiltinHelpFormatter) OptionException(joptsimple.OptionException) OptionSet(joptsimple.OptionSet) OptionParser(joptsimple.OptionParser)

Aggregations

OptionException (joptsimple.OptionException)23 OptionSet (joptsimple.OptionSet)20 OptionParser (joptsimple.OptionParser)14 File (java.io.File)4 IOException (java.io.IOException)4 List (java.util.List)4 ArrayList (java.util.ArrayList)3 ThreadFactoryBuilder (com.google.common.util.concurrent.ThreadFactoryBuilder)2 BitsquareEnvironment (io.bitsquare.app.BitsquareEnvironment)2 PrintWriter (java.io.PrintWriter)2 LinkedList (java.util.LinkedList)2 ThreadFactory (java.util.concurrent.ThreadFactory)2 BuiltinHelpFormatter (joptsimple.BuiltinHelpFormatter)2 VoldemortApplicationException (voldemort.VoldemortApplicationException)2 BufferedReader (java.io.BufferedReader)1 FileInputStream (java.io.FileInputStream)1 InputStreamReader (java.io.InputStreamReader)1 PrintStream (java.io.PrintStream)1 StringWriter (java.io.StringWriter)1 Socket (java.net.Socket)1