private OptionParser buildOptionParser() { OptionParser parser = new OptionParser(); parser .accepts(ARGUMENT_EXPERIMENT, "Pre selected experiment") .withRequiredArg() .ofType(String.class); parser.accepts(ARGUMENT_EXPERIMENT_LIST, "Retrieves the current list of available experiments"); parser.accepts(ARGUMENT_HELP, "Displays this help").forHelp(); parser.allowsUnrecognizedOptions(); return parser; }
private static OptionParser buildParser() { final OptionParser parser = new OptionParser() { { acceptsAll(asList(HELP_OPTION_SHORT, HELP_OPTION_LONG), "This help").forHelp(); acceptsAll( asList(UNINSTALL_OPTION_SHORT, UNINSTALL_OPTION_LONG), "Remove registry settings"); acceptsAll( asList(VERBOSE_OPTION_SHORT, VERBOSE_OPTION_LONG), "Enable verbose application messages"); acceptsAll(asList(FILE_OPTION_SHORT, FILE_OPTION_LONG), "File to load at start") .withRequiredArg() .ofType(File.class); accepts(PASSWORD_OPTION, "Password for a local File, server or client") .withRequiredArg(); acceptsAll( asList(PORTABLE_OPTION_SHORT, PORTABLE_OPTION_LONG), "Enable portable preferences"); accepts(PORTABLE_FILE_OPTION, "Enable portable preferences and specify the file") .withRequiredArg() .ofType(File.class); accepts( PORT_OPTION, "Network port server is running on (default: " + JpaNetworkServer.DEFAULT_PORT + ")") .withRequiredArg() .ofType(Integer.class); accepts(HOST_OPTION, "Server host name or address") .requiredIf(PORT_OPTION) .withRequiredArg(); accepts(SERVER_OPTION, "Runs as a server using the specified file") .withRequiredArg() .ofType(File.class); } }; parser.allowsUnrecognizedOptions(); return parser; }
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(USER_DATA_DIR_KEY, description("User data directory", DEFAULT_USER_DATA_DIR)) .withRequiredArg(); parser .accepts(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) initAppDir(bitsquareEnvironment.getProperty(BitsquareEnvironment.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); }