use of joptsimple.OptionException in project geode by apache.
the class Launcher method parseOptions.
private int parseOptions(final String... args) {
OptionSet parsedOptions;
try {
parsedOptions = this.commandLineParser.parse(args);
} catch (OptionException e) {
System.err.println(CliStrings.format(MSG_INVALID_COMMAND_OR_OPTION, CliUtil.arrayToString(args)));
return ExitShellRequest.FATAL_EXIT.getExitCode();
}
boolean launchShell = true;
boolean onlyPrintUsage = parsedOptions.has(HELP_OPTION);
if (parsedOptions.has(EXECUTE_OPTION) || onlyPrintUsage) {
launchShell = false;
}
Gfsh gfsh = null;
try {
gfsh = Gfsh.getInstance(launchShell, args, new GfshConfig());
this.startupTimeLogHelper.logStartupTime();
} catch (ClassNotFoundException cnfex) {
log(cnfex, gfsh);
} catch (IOException ioex) {
log(ioex, gfsh);
} catch (IllegalStateException isex) {
System.err.println("ERROR : " + isex.getMessage());
}
ExitShellRequest exitRequest = ExitShellRequest.NORMAL_EXIT;
if (gfsh != null) {
try {
if (launchShell) {
gfsh.start();
gfsh.waitForComplete();
exitRequest = gfsh.getExitShellRequest();
} else if (onlyPrintUsage) {
printUsage(gfsh, System.out);
} else {
@SuppressWarnings("unchecked") List<String> commandsToExecute = (List<String>) parsedOptions.valuesOf(EXECUTE_OPTION);
// Execute all of the commands in the list, one at a time.
for (int i = 0; i < commandsToExecute.size() && exitRequest == ExitShellRequest.NORMAL_EXIT; i++) {
String command = commandsToExecute.get(i);
// sanitize the output string to not show the password
System.out.println(GfshParser.LINE_SEPARATOR + "(" + (i + 1) + ") Executing - " + GfshHistory.redact(command) + GfshParser.LINE_SEPARATOR);
if (!gfsh.executeScriptLine(command) || gfsh.getLastExecutionStatus() != 0) {
exitRequest = ExitShellRequest.FATAL_EXIT;
}
}
}
} catch (InterruptedException iex) {
log(iex, gfsh);
}
}
return exitRequest.getExitCode();
}
use of joptsimple.OptionException in project bitsquare by bitsquare.
the class BitsquareExecutable method execute.
public void execute(String[] args) throws Exception {
OptionParser parser = new OptionParser();
parser.accepts(HELP_KEY, "This help text").forHelp();
this.customizeOptionParsing(parser);
OptionSet options;
try {
options = parser.parse(args);
if (options.has(HELP_KEY)) {
parser.printHelpOn(System.out);
System.exit(EXIT_SUCCESS);
return;
}
} catch (OptionException ex) {
System.out.println("error: " + ex.getMessage());
System.out.println();
parser.printHelpOn(System.out);
System.exit(EXIT_FAILURE);
return;
}
this.doExecute(options);
}
use of joptsimple.OptionException in project bitsquare by bitsquare.
the class StatisticsMain method main.
public static void main(String[] args) throws Exception {
final ThreadFactory threadFactory = new ThreadFactoryBuilder().setNameFormat("Statistics").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_statistics");
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(StatisticsMain.class.getClassLoader());
new StatisticsMain().execute(args);
}
Aggregations