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);
}
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);
}
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;
}
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"));
}
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);
}
Aggregations