Search in sources :

Example 16 with OptionSet

use of joptsimple.OptionSet in project syncany by syncany.

the class GenlinkCommand method parseOptions.

@Override
public GenlinkOperationOptions parseOptions(String[] operationArgs) {
    GenlinkOperationOptions operationOptions = new GenlinkOperationOptions();
    OptionParser parser = new OptionParser();
    OptionSpec<Void> optionMachineReadable = parser.acceptsAll(asList("m", "machine-readable"));
    OptionSpec<Void> optionShort = parser.acceptsAll(asList("s", "short"));
    parser.allowsUnrecognizedOptions();
    OptionSet options = parser.parse(operationArgs);
    // --machine-readable, -m
    machineReadableOutput = options.has(optionMachineReadable);
    // --short, -s
    operationOptions.setShortUrl(options.has(optionShort));
    return operationOptions;
}
Also used : GenlinkOperationOptions(org.syncany.operations.init.GenlinkOperationOptions) OptionSet(joptsimple.OptionSet) OptionParser(joptsimple.OptionParser)

Example 17 with OptionSet

use of joptsimple.OptionSet in project syncany by syncany.

the class LogCommand method parseOptions.

@Override
public LogOperationOptions parseOptions(String[] operationArgs) throws Exception {
    LogOperationOptions operationOptions = new LogOperationOptions();
    OptionParser parser = new OptionParser();
    parser.allowsUnrecognizedOptions();
    OptionSpec<Integer> optionMaxDatabaseVersionCountStr = parser.acceptsAll(asList("n", "database-count")).withRequiredArg().ofType(Integer.class);
    OptionSpec<Integer> optionStartDatabaseVersionIndexStr = parser.acceptsAll(asList("s", "database-start")).withRequiredArg().ofType(Integer.class);
    OptionSpec<Integer> optionMaxFileHistoryCountStr = parser.acceptsAll(asList("f", "file-count")).withRequiredArg().ofType(Integer.class);
    OptionSpec<Void> optionExcludeEmpty = parser.acceptsAll(asList("x", "exclude-empty"));
    OptionSet options = parser.parse(operationArgs);
    // -x, --exclude-empty
    excludeEmpty = options.has(optionExcludeEmpty);
    // -n, --database-count=..
    if (options.has(optionMaxDatabaseVersionCountStr)) {
        operationOptions.setMaxDatabaseVersionCount(options.valueOf(optionMaxDatabaseVersionCountStr));
    }
    // -s, --database-start=..
    if (options.has(optionStartDatabaseVersionIndexStr)) {
        operationOptions.setStartDatabaseVersionIndex(options.valueOf(optionStartDatabaseVersionIndexStr));
    }
    // -f, --file-count=..
    if (options.has(optionMaxFileHistoryCountStr)) {
        operationOptions.setMaxFileHistoryCount(options.valueOf(optionMaxFileHistoryCountStr));
    }
    return operationOptions;
}
Also used : OptionSet(joptsimple.OptionSet) LogOperationOptions(org.syncany.operations.log.LogOperationOptions) OptionParser(joptsimple.OptionParser)

Example 18 with OptionSet

use of joptsimple.OptionSet in project syncany by syncany.

the class PluginCommand method parseOptions.

@Override
public PluginOperationOptions parseOptions(String[] operationArgs) throws Exception {
    PluginOperationOptions operationOptions = new PluginOperationOptions();
    OptionParser parser = new OptionParser();
    OptionSpec<Void> optionLocal = parser.acceptsAll(asList("L", "local-only"));
    OptionSpec<Void> optionRemote = parser.acceptsAll(asList("R", "remote-only"));
    OptionSpec<Void> optionSnapshots = parser.acceptsAll(asList("s", "snapshot", "snapshots"));
    OptionSpec<Void> optionMinimalOutput = parser.acceptsAll(asList("m", "minimal-output"));
    OptionSpec<String> optionApiEndpoint = parser.acceptsAll(asList("a", "api-endpoint")).withRequiredArg();
    OptionSet options = parser.parse(operationArgs);
    // Files
    List<?> nonOptionArgs = options.nonOptionArguments();
    if (nonOptionArgs.size() == 0) {
        throw new Exception("Invalid syntax, please specify an action (list, install, remove, update).");
    }
    // <action>
    String actionStr = nonOptionArgs.get(0).toString();
    PluginOperationAction action = parsePluginAction(actionStr);
    operationOptions.setAction(action);
    // --minimal-output
    minimalOutput = options.has(optionMinimalOutput);
    // --snapshots
    operationOptions.setSnapshots(options.has(optionSnapshots));
    // --api-endpoint
    if (options.has(optionApiEndpoint)) {
        operationOptions.setApiEndpoint(options.valueOf(optionApiEndpoint));
    }
    // install|remove <plugin-id>
    if (action == PluginOperationAction.INSTALL || action == PluginOperationAction.REMOVE) {
        if (nonOptionArgs.size() != 2) {
            throw new Exception("Invalid syntax, please specify a plugin ID.");
        }
        // <plugin-id>
        String pluginId = nonOptionArgs.get(1).toString();
        operationOptions.setPluginId(pluginId);
    } else // --local-only, --remote-only
    if (action == PluginOperationAction.LIST) {
        if (options.has(optionLocal)) {
            operationOptions.setListMode(PluginListMode.LOCAL);
        } else if (options.has(optionRemote)) {
            operationOptions.setListMode(PluginListMode.REMOTE);
        } else {
            operationOptions.setListMode(PluginListMode.ALL);
        }
        // <plugin-id> (optional in 'list' or 'update')
        if (nonOptionArgs.size() == 2) {
            String pluginId = nonOptionArgs.get(1).toString();
            operationOptions.setPluginId(pluginId);
        }
    } else if (action == PluginOperationAction.UPDATE && nonOptionArgs.size() == 2) {
        String pluginId = nonOptionArgs.get(1).toString();
        operationOptions.setPluginId(pluginId);
    }
    return operationOptions;
}
Also used : PluginOperationAction(org.syncany.operations.plugin.PluginOperationAction) PluginOperationOptions(org.syncany.operations.plugin.PluginOperationOptions) OptionSet(joptsimple.OptionSet) OptionParser(joptsimple.OptionParser)

Example 19 with OptionSet

use of joptsimple.OptionSet 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 20 with OptionSet

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

Aggregations

OptionSet (joptsimple.OptionSet)121 OptionParser (joptsimple.OptionParser)93 File (java.io.File)40 OptionException (joptsimple.OptionException)22 IOException (java.io.IOException)20 List (java.util.List)16 Cluster (voldemort.cluster.Cluster)13 ArrayList (java.util.ArrayList)12 Test (org.junit.Test)12 StoreDefinition (voldemort.store.StoreDefinition)12 ClusterMapper (voldemort.xml.ClusterMapper)10 StoreDefinitionsMapper (voldemort.xml.StoreDefinitionsMapper)9 FileNotFoundException (java.io.FileNotFoundException)6 VoldemortException (voldemort.VoldemortException)6 BufferedReader (java.io.BufferedReader)5 Properties (java.util.Properties)5 OptionSpec (joptsimple.OptionSpec)5 Node (voldemort.cluster.Node)5 ByteArray (voldemort.utils.ByteArray)5 Closer (com.google.common.io.Closer)4