Search in sources :

Example 66 with OptionParser

use of joptsimple.OptionParser in project syncany by syncany.

the class StatusCommand method parseOptions.

@Override
public StatusOperationOptions parseOptions(String[] operationArgs) throws Exception {
    StatusOperationOptions operationOptions = new StatusOperationOptions();
    OptionParser parser = new OptionParser();
    parser.allowsUnrecognizedOptions();
    OptionSpec<Void> optionForceChecksum = parser.acceptsAll(asList("f", "force-checksum"));
    OptionSpec<Void> optionNoDeleteUpload = parser.acceptsAll(asList("D", "no-delete"));
    OptionSet options = parser.parse(operationArgs);
    // --force-checksum
    operationOptions.setForceChecksum(options.has(optionForceChecksum));
    // -D, --no-delete
    operationOptions.setDelete(!options.has(optionNoDeleteUpload));
    return operationOptions;
}
Also used : OptionSet(joptsimple.OptionSet) StatusOperationOptions(org.syncany.operations.status.StatusOperationOptions) OptionParser(joptsimple.OptionParser)

Example 67 with OptionParser

use of joptsimple.OptionParser in project syncany by syncany.

the class ConnectCommand method parseOptions.

@Override
public ConnectOperationOptions parseOptions(String[] operationArgs) throws Exception {
    ConnectOperationOptions operationOptions = new ConnectOperationOptions();
    OptionParser parser = new OptionParser();
    OptionSpec<String> optionPlugin = parser.acceptsAll(asList("P", "plugin")).withRequiredArg();
    OptionSpec<String> optionPluginOpts = parser.acceptsAll(asList("o", "plugin-option")).withRequiredArg();
    OptionSpec<Void> optionAddDaemon = parser.acceptsAll(asList("n", "add-daemon"));
    OptionSpec<String> optionPassword = parser.acceptsAll(asList("password")).withRequiredArg();
    OptionSet options = parser.parse(operationArgs);
    List<?> nonOptionArgs = options.nonOptionArguments();
    // Set interactivity mode
    isInteractive = !options.has(optionPlugin) && !options.has(optionPassword);
    // Plugin
    TransferSettings transferSettings = null;
    if (nonOptionArgs.size() == 1) {
        String connectLink = (String) nonOptionArgs.get(0);
        operationOptions.setStrategy(ConnectOptionsStrategy.CONNECTION_LINK);
        operationOptions.setConnectLink(connectLink);
        transferSettings = null;
    } else if (nonOptionArgs.size() == 0) {
        operationOptions.setStrategy(ConnectOptionsStrategy.CONNECTION_TO);
        operationOptions.setConnectLink(null);
        transferSettings = createTransferSettingsFromOptions(options, optionPlugin, optionPluginOpts);
    } else {
        throw new Exception("Invalid syntax.");
    }
    ConfigTO configTO = createConfigTO(transferSettings);
    operationOptions.setLocalDir(localDir);
    operationOptions.setConfigTO(configTO);
    operationOptions.setDaemon(options.has(optionAddDaemon));
    operationOptions.setPassword(validateAndGetPassword(options, optionPassword));
    return operationOptions;
}
Also used : TransferSettings(org.syncany.plugins.transfer.TransferSettings) ConfigTO(org.syncany.config.to.ConfigTO) OptionSet(joptsimple.OptionSet) OptionParser(joptsimple.OptionParser) ConnectOperationOptions(org.syncany.operations.init.ConnectOperationOptions)

Example 68 with OptionParser

use of joptsimple.OptionParser in project syncany by syncany.

the class DownCommand method parseOptions.

public DownOperationOptions parseOptions(String[] operationArguments) {
    DownOperationOptions operationOptions = new DownOperationOptions();
    OptionParser parser = new OptionParser();
    parser.allowsUnrecognizedOptions();
    OptionSpec<String> optionConflictStrategy = parser.acceptsAll(asList("C", "conflict-strategy")).withRequiredArg();
    OptionSpec<Void> optionNoApply = parser.acceptsAll(asList("A", "no-apply"));
    OptionSet options = parser.parse(operationArguments);
    // --conflict-strategy=<strategy>
    if (options.has(optionConflictStrategy)) {
        String conflictStrategyStr = options.valueOf(optionConflictStrategy).toUpperCase();
        operationOptions.setConflictStrategy(DownConflictStrategy.valueOf(conflictStrategyStr));
    }
    // --no-apply
    if (options.has(optionNoApply)) {
        operationOptions.setApplyChanges(false);
    }
    return operationOptions;
}
Also used : DownOperationOptions(org.syncany.operations.down.DownOperationOptions) OptionSet(joptsimple.OptionSet) OptionParser(joptsimple.OptionParser)

Example 69 with OptionParser

use of joptsimple.OptionParser in project syncany by syncany.

the class CleanupCommand method parseOptions.

@Override
public CleanupOperationOptions parseOptions(String[] operationArgs) throws Exception {
    CleanupOperationOptions operationOptions = new CleanupOperationOptions();
    OptionParser parser = new OptionParser();
    parser.allowsUnrecognizedOptions();
    OptionSpec<Void> optionForce = parser.acceptsAll(asList("f", "force"));
    OptionSpec<Void> optionNoOlderVersionRemoval = parser.acceptsAll(asList("O", "no-delete-older-than"));
    OptionSpec<Void> optionNoVersionRemovalByInterval = parser.acceptsAll(asList("I", "no-delete-interval"));
    OptionSpec<Void> optionNoRemoveTempFiles = parser.acceptsAll(asList("T", "no-temp-removal"));
    OptionSpec<String> optionKeepMinTime = parser.acceptsAll(asList("o", "delete-older-than")).withRequiredArg().ofType(String.class);
    OptionSet options = parser.parse(operationArgs);
    // -F, --force
    operationOptions.setForce(options.has(optionForce));
    // -V, --no-version-removal
    operationOptions.setRemoveOldVersions(!options.has(optionNoOlderVersionRemoval));
    // -T, --no-temp-removal
    operationOptions.setRemoveUnreferencedTemporaryFiles(!options.has(optionNoRemoveTempFiles));
    // -I, --no-delete-interval
    operationOptions.setRemoveVersionsByInterval(!options.has(optionNoVersionRemovalByInterval));
    // -o=<time>, --delete-older-than=<time>
    if (options.has(optionKeepMinTime)) {
        long keepDeletedFilesForSeconds = CommandLineUtil.parseTimePeriod(options.valueOf(optionKeepMinTime));
        if (keepDeletedFilesForSeconds < 0) {
            throw new Exception("Invalid value for --delete-older-than==" + keepDeletedFilesForSeconds + "; must be >= 0");
        }
        operationOptions.setMinKeepSeconds(keepDeletedFilesForSeconds);
    }
    // Parse 'status' options
    operationOptions.setStatusOptions(parseStatusOptions(operationArgs));
    return operationOptions;
}
Also used : CleanupOperationOptions(org.syncany.operations.cleanup.CleanupOperationOptions) OptionSet(joptsimple.OptionSet) OptionParser(joptsimple.OptionParser)

Example 70 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)121 OptionSet (joptsimple.OptionSet)94 File (java.io.File)35 OptionException (joptsimple.OptionException)16 IOException (java.io.IOException)15 List (java.util.List)13 Test (org.junit.Test)13 ArrayList (java.util.ArrayList)11 Cluster (voldemort.cluster.Cluster)8 FileNotFoundException (java.io.FileNotFoundException)6 StoreDefinition (voldemort.store.StoreDefinition)6 Closer (com.google.common.io.Closer)5 BufferedReader (java.io.BufferedReader)5 Properties (java.util.Properties)5 OptionSpec (joptsimple.OptionSpec)5 Node (voldemort.cluster.Node)5 ByteArray (voldemort.utils.ByteArray)5 ClusterMapper (voldemort.xml.ClusterMapper)5 MongoClientURI (com.mongodb.MongoClientURI)4 FileReader (java.io.FileReader)4