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 bisq-core by bisq-network.
the class BisqExecutable 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 hazelcast-simulator by hazelcast.
the class CliUtils method initOptionsWithHelp.
public static OptionSet initOptionsWithHelp(OptionParser parser, String help, String[] args) {
try {
OptionSpec helpSpec = parser.accepts("help", "Shows the help.").forHelp();
OptionSet options = parser.parse(args);
if (options.has(helpSpec)) {
if (help != null) {
printHelp(help);
}
printHelpAndExit(parser, System.out);
}
return options;
} catch (OptionException e) {
throw new CommandLineExitException(e.getMessage() + ". Use --help to get overview of the help options.");
}
}
use of joptsimple.OptionException in project LanternServer by LanternPowered.
the class LanternServerLaunch method main.
public void main(String[] args) {
final LanternClassLoader classLoader = LanternClassLoader.get();
// Exclude the ASM library
classLoader.addTransformerExclusion(Exclusion.forPackage("org.objectweb.asm"));
classLoader.addTransformerExclusion(Exclusion.forPackage("org.lanternpowered.server.transformer"));
classLoader.addTransformerExclusion(Exclusion.forClass("org.lanternpowered.server.util.BytecodeUtils"));
classLoader.addTransformer(new FinalFieldClassTransformer());
classLoader.addTransformer(new FastValueContainerClassTransformer());
// Get the default logger
final Logger logger = LoggerFactory.getLogger(InternalPluginsInfo.Implementation.IDENTIFIER);
try {
// Create the shared option parser
final OptionParser optionParser = new OptionParser();
optionParser.allowsUnrecognizedOptions();
final OptionSpec<Void> version = optionParser.acceptsAll(Arrays.asList("version", "v"), "Display the Lantern version");
if (optionParser.parse(args).has(version)) {
final Package pack = Platform.class.getPackage();
logger.info(pack.getImplementationTitle() + ' ' + pack.getImplementationVersion());
logger.info(pack.getSpecificationTitle() + ' ' + pack.getSpecificationVersion());
return;
}
final OptionSpec<Void> help = optionParser.acceptsAll(Arrays.asList("help", "h", "?"), "Show this help text").forHelp();
// Initialize the injector
final LanternModule module = new LanternModule(logger, args, optionParser);
final Injector injector = Guice.createInjector(Stage.DEVELOPMENT, module);
logger.info("Instantiated the Injector in {} mode.", Environment.get().name().toLowerCase());
// Create the server instance
final LanternServer lanternServer = injector.getInstance(LanternServer.class);
// Initialize and start the server
lanternServer.initialize();
try {
final Field field = OptionParser.class.getDeclaredField("allowsUnrecognizedOptions");
field.setAccessible(true);
field.set(optionParser, false);
optionParser.parse(args);
} catch (OptionException e) {
logger.warn("Something went wrong while parsing options", e);
} catch (Exception e) {
logger.error("Unexpected error", e);
}
// annotations will be detected
if (optionParser.parse(args).has(help)) {
if (System.console() != null) {
// Terminal is (very likely) supported, use the terminal width provided by jline
final Terminal terminal = TerminalConsoleAppender.getTerminal();
if (terminal != null) {
optionParser.formatHelpWith(new BuiltinHelpFormatter(terminal.getWidth(), 3));
}
}
optionParser.printHelpOn(System.err);
return;
}
lanternServer.start();
} catch (Throwable t) {
logger.error("Error during server startup.", t);
System.exit(1);
}
}
Aggregations