use of joptsimple.OptionParser in project spring-framework by spring-projects.
the class JOptCommandLinePropertySourceTests method withNoArg.
@Test
public void withNoArg() {
OptionParser parser = new OptionParser();
parser.accepts("o1");
parser.accepts("o2");
OptionSet options = parser.parse("--o1");
PropertySource<?> ps = new JOptCommandLinePropertySource(options);
assertThat(ps.containsProperty("o1"), is(true));
assertThat(ps.containsProperty("o2"), is(false));
assertThat((String) ps.getProperty("o1"), equalTo(""));
assertThat(ps.getProperty("o2"), nullValue());
}
use of joptsimple.OptionParser in project jgnash by ccavanaugh.
the class jGnashFx method main.
public static void main(final String[] args) throws Exception {
if (OS.getJavaVersion() < 1.8f) {
System.out.println(ResourceUtils.getString("Message.JVM8"));
System.out.println(ResourceUtils.getString("Message.Version") + " " + System.getProperty("java.version") + "\n");
// try and show a dialog
JOptionPane.showMessageDialog(null, ResourceUtils.getString("Message.JVM8"), ResourceUtils.getString("Title.Error"), JOptionPane.ERROR_MESSAGE);
return;
}
if (OS.getJavaRelease() < OS.JVM_RELEASE_71) {
JOptionPane.showMessageDialog(null, ResourceUtils.getString("Message.JFX"), ResourceUtils.getString("Title.Error"), JOptionPane.ERROR_MESSAGE);
return;
}
// Register the default exception handler
Thread.setDefaultUncaughtExceptionHandler(new StaticUIMethods.ExceptionHandler());
configureLogging();
OptionParser parser = buildParser();
try {
final OptionSet options = parser.parse(args);
// Does the user want to uninstall and clear their registry settings
if (options.has(UNINSTALL_OPTION_SHORT)) {
PortablePreferences.deleteUserPreferences();
System.exit(0);
}
// Needs to be checked for launching
if (options.has(VERBOSE_OPTION_SHORT)) {
System.setProperty("javafx.verbose", "true");
}
// Check to see if portable preferences are being used
if (options.has(PORTABLE_FILE_OPTION)) {
final File file = (File) options.valueOf(PORTABLE_FILE_OPTION);
if (file.exists()) {
PortablePreferences.initPortablePreferences(file.getAbsolutePath());
}
} else if (options.has(PORTABLE_OPTION_SHORT)) {
// simple use of portable preferences
PortablePreferences.initPortablePreferences(null);
}
if (options.has(PORT_OPTION)) {
port = (Integer) options.valueOf(PORT_OPTION);
}
if (options.has(PASSWORD_OPTION)) {
password = ((String) options.valueOf(PASSWORD_OPTION)).toCharArray();
}
if (options.has(FILE_OPTION_SHORT)) {
final File file = (File) options.valueOf(FILE_OPTION_SHORT);
if (file.exists()) {
dataFile = file;
}
} else if (!options.nonOptionArguments().isEmpty() && dataFile == null) {
// Check for no-option version of a file load
for (final Object object : options.nonOptionArguments()) {
if (object instanceof String) {
if (Files.exists(Paths.get((String) object))) {
dataFile = new File((String) object);
break;
} else {
System.err.println(object + " was not a valid file");
// force an exit with an error
System.exit(1);
}
}
}
}
if (options.has(HOST_OPTION)) {
host = (String) options.valueOf(HOST_OPTION);
}
if (options.has(SERVER_OPTION)) {
final File file = (File) options.valueOf(SERVER_OPTION);
if (file.exists()) {
serverFile = file;
}
}
if (serverFile != null) {
// not needed anymore, trigger GC
parser = null;
startServer();
} else {
// not needed anymore, trigger GC
parser = null;
setupNetworking();
launch(args);
}
} catch (final Exception exception) {
if (parser != null) {
parser.printHelpOn(System.err);
}
}
}
use of joptsimple.OptionParser 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.OptionParser in project aic-expresso by aic-sri-international.
the class SymbolicShell method getConsole.
private static ConsoleIterator getConsole(String[] args) {
ConsoleIterator result = null;
OptionParser parser = new OptionParser();
OptionSpec<String> consoleType = parser.accepts("console", "Console type <gui> or <default>").withRequiredArg().ofType(String.class);
OptionSet options = parser.parse(args);
if (options.has(consoleType)) {
if ("gui".equalsIgnoreCase(options.valueOf(consoleType))) {
result = new GUIConsoleIterator();
}
}
if (result == null) {
result = new DefaultConsoleIterator();
}
return result;
}
use of joptsimple.OptionParser in project syncany by syncany.
the class PluginCommand method parseOptions.
@Override
public PluginOperationOptions parseOptions(String[] operationArgs) throws Exception {
PluginOperationOptions operationOptions = new PluginOperationOptions();
OptionParser parser = new OptionParser();
OptionSpec<Void> optionLocal = parser.acceptsAll(asList("L", "local-only"));
OptionSpec<Void> optionRemote = parser.acceptsAll(asList("R", "remote-only"));
OptionSpec<Void> optionSnapshots = parser.acceptsAll(asList("s", "snapshot", "snapshots"));
OptionSpec<Void> optionMinimalOutput = parser.acceptsAll(asList("m", "minimal-output"));
OptionSpec<String> optionApiEndpoint = parser.acceptsAll(asList("a", "api-endpoint")).withRequiredArg();
OptionSet options = parser.parse(operationArgs);
// Files
List<?> nonOptionArgs = options.nonOptionArguments();
if (nonOptionArgs.size() == 0) {
throw new Exception("Invalid syntax, please specify an action (list, install, remove, update).");
}
// <action>
String actionStr = nonOptionArgs.get(0).toString();
PluginOperationAction action = parsePluginAction(actionStr);
operationOptions.setAction(action);
// --minimal-output
minimalOutput = options.has(optionMinimalOutput);
// --snapshots
operationOptions.setSnapshots(options.has(optionSnapshots));
// --api-endpoint
if (options.has(optionApiEndpoint)) {
operationOptions.setApiEndpoint(options.valueOf(optionApiEndpoint));
}
// install|remove <plugin-id>
if (action == PluginOperationAction.INSTALL || action == PluginOperationAction.REMOVE) {
if (nonOptionArgs.size() != 2) {
throw new Exception("Invalid syntax, please specify a plugin ID.");
}
// <plugin-id>
String pluginId = nonOptionArgs.get(1).toString();
operationOptions.setPluginId(pluginId);
} else // --local-only, --remote-only
if (action == PluginOperationAction.LIST) {
if (options.has(optionLocal)) {
operationOptions.setListMode(PluginListMode.LOCAL);
} else if (options.has(optionRemote)) {
operationOptions.setListMode(PluginListMode.REMOTE);
} else {
operationOptions.setListMode(PluginListMode.ALL);
}
// <plugin-id> (optional in 'list' or 'update')
if (nonOptionArgs.size() == 2) {
String pluginId = nonOptionArgs.get(1).toString();
operationOptions.setPluginId(pluginId);
}
} else if (action == PluginOperationAction.UPDATE && nonOptionArgs.size() == 2) {
String pluginId = nonOptionArgs.get(1).toString();
operationOptions.setPluginId(pluginId);
}
return operationOptions;
}
Aggregations