Search in sources :

Example 1 with OptionException

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);
}
Also used : ThreadFactory(java.util.concurrent.ThreadFactory) ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) OptionException(joptsimple.OptionException) BitsquareEnvironment(io.bitsquare.app.BitsquareEnvironment) OptionSet(joptsimple.OptionSet) OptionParser(joptsimple.OptionParser)

Example 2 with OptionException

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);
}
Also used : OptionException(joptsimple.OptionException) OptionSet(joptsimple.OptionSet) OptionParser(joptsimple.OptionParser)

Example 3 with OptionException

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);
}
Also used : OptionException(joptsimple.OptionException) OptionSet(joptsimple.OptionSet) OptionParser(joptsimple.OptionParser)

Example 4 with OptionException

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.");
    }
}
Also used : OptionSpec(joptsimple.OptionSpec) OptionException(joptsimple.OptionException) OptionSet(joptsimple.OptionSet)

Example 5 with OptionException

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);
    }
}
Also used : LanternClassLoader(org.lanternpowered.launch.LanternClassLoader) OptionException(joptsimple.OptionException) Logger(org.slf4j.Logger) OptionParser(joptsimple.OptionParser) Terminal(org.jline.terminal.Terminal) OptionException(joptsimple.OptionException) Field(java.lang.reflect.Field) BuiltinHelpFormatter(joptsimple.BuiltinHelpFormatter) Injector(com.google.inject.Injector) FastValueContainerClassTransformer(org.lanternpowered.server.transformer.data.FastValueContainerClassTransformer) LanternModule(org.lanternpowered.server.inject.LanternModule) FinalFieldClassTransformer(org.lanternpowered.server.transformer.FinalFieldClassTransformer)

Aggregations

OptionException (joptsimple.OptionException)39 OptionSet (joptsimple.OptionSet)30 OptionParser (joptsimple.OptionParser)25 File (java.io.File)7 IOException (java.io.IOException)6 List (java.util.List)5 PrintWriter (java.io.PrintWriter)4 ArrayList (java.util.ArrayList)4 BuiltinHelpFormatter (joptsimple.BuiltinHelpFormatter)4 OptionSpec (joptsimple.OptionSpec)4 ThreadFactoryBuilder (com.google.common.util.concurrent.ThreadFactoryBuilder)3 StringWriter (java.io.StringWriter)3 ThreadFactory (java.util.concurrent.ThreadFactory)3 BisqEnvironment (io.bisq.core.app.BisqEnvironment)2 BitsquareEnvironment (io.bitsquare.app.BitsquareEnvironment)2 FileInputStream (java.io.FileInputStream)2 HashSet (java.util.HashSet)2 LinkedList (java.util.LinkedList)2 Properties (java.util.Properties)2 Logger (org.slf4j.Logger)2