Search in sources :

Example 6 with OptionParser

use of joptsimple.OptionParser in project jackrabbit-oak by apache.

the class OptionParserFactory method create.

public static OptionParser create() {
    OptionParser op = new OptionParser();
    addUsageOptions(op);
    addBlobOptions(op);
    addRdbOptions(op);
    addPathsOptions(op);
    addVersioningOptions(op);
    addMiscOptions(op);
    return op;
}
Also used : OptionParser(joptsimple.OptionParser)

Example 7 with OptionParser

use of joptsimple.OptionParser in project gradle by gradle.

the class Main method main.

public static void main(String[] args) throws IOException {
    OptionParser parser = new OptionParser();
    ArgumentAcceptingOptionSpec<String> projectFlag = parser.accepts("project-dir", "Gradle project directory").withRequiredArg();
    ArgumentAcceptingOptionSpec<String> gradleInstallFlag = parser.accepts("gradle-install", "Gradle installation to run the build with").withRequiredArg();
    OptionSpecBuilder sync = parser.accepts("sync", "Simulate Gradle project synchronization");
    OptionSpecBuilder embeddedFlag = parser.accepts("embedded", "Run build in-process");
    OptionSet options = parser.parse(args);
    if (!options.has(projectFlag)) {
        System.out.println("No project directory specified.");
        System.out.println();
        parser.printHelpOn(System.out);
        return;
    }
    File buildDir = new File(options.valueOf(projectFlag));
    File gradleInstallDir = options.hasArgument(gradleInstallFlag) ? new File(options.valueOf(gradleInstallFlag)) : null;
    boolean embedded = options.hasArgument(embeddedFlag);
    boolean hasSimulation = options.has(sync);
    if (options.has(sync) || hasSimulation) {
        // defaults to 'sync', which is the only mode right now, hence the weird test above
        fetch(buildDir, gradleInstallDir, embedded);
    }
    System.exit(0);
}
Also used : OptionSpecBuilder(joptsimple.OptionSpecBuilder) OptionSet(joptsimple.OptionSet) OptionParser(joptsimple.OptionParser) File(java.io.File)

Example 8 with OptionParser

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);
        }
    }
}
Also used : StaticUIMethods(jgnash.uifx.StaticUIMethods) OptionSet(joptsimple.OptionSet) OptionParser(joptsimple.OptionParser) File(java.io.File) FileNotFoundException(java.io.FileNotFoundException)

Example 9 with OptionParser

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);
}
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 10 with OptionParser

use of joptsimple.OptionParser 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)

Aggregations

OptionParser (joptsimple.OptionParser)199 OptionSet (joptsimple.OptionSet)151 File (java.io.File)58 IOException (java.io.IOException)29 Test (org.junit.Test)28 OptionException (joptsimple.OptionException)25 ArrayList (java.util.ArrayList)21 Properties (java.util.Properties)16 List (java.util.List)15 OptionSpec (joptsimple.OptionSpec)14 Test (org.junit.jupiter.api.Test)12 VerifiableProperties (com.github.ambry.config.VerifiableProperties)11 FileNotFoundException (java.io.FileNotFoundException)9 BufferedReader (java.io.BufferedReader)8 ArgumentAcceptingOptionSpec (joptsimple.ArgumentAcceptingOptionSpec)8 FileReader (java.io.FileReader)7 OptionSpecBuilder (joptsimple.OptionSpecBuilder)7 Closer (com.google.common.io.Closer)6 Cluster (voldemort.cluster.Cluster)6 StoreDefinition (voldemort.store.StoreDefinition)6