Search in sources :

Example 11 with OptionSet

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

use of joptsimple.OptionSet in project syncany by syncany.

the class CommandLineClient method start.

public int start() throws Exception {
    try {
        // Define global options
        OptionParser parser = new OptionParser();
        parser.allowsUnrecognizedOptions();
        OptionSpec<Void> optionHelp = parser.acceptsAll(asList("h", "help"));
        OptionSpec<File> optionLocalDir = parser.acceptsAll(asList("l", "localdir")).withRequiredArg().ofType(File.class);
        OptionSpec<String> optionLog = parser.acceptsAll(asList("log")).withRequiredArg();
        OptionSpec<Void> optionLogPrint = parser.acceptsAll(asList("print"));
        OptionSpec<String> optionLogLevel = parser.acceptsAll(asList("loglevel")).withOptionalArg();
        OptionSpec<Void> optionDebug = parser.acceptsAll(asList("d", "debug"));
        OptionSpec<Void> optionShortVersion = parser.acceptsAll(asList("v"));
        OptionSpec<Void> optionFullVersion = parser.acceptsAll(asList("vv"));
        // Parse global options and operation name
        OptionSet options = parser.parse(args);
        List<?> nonOptions = options.nonOptionArguments();
        // -v, -vv, --version
        int versionOptionsCode = initVersionOptions(options, optionShortVersion, optionFullVersion);
        if (versionOptionsCode != -1) {
            // Version information was displayed, exit.
            return versionOptionsCode;
        }
        int helpOrUsageCode = initHelpOrUsage(options, nonOptions, optionHelp);
        if (helpOrUsageCode != -1) {
            // Help or usage was displayed, exit.
            return helpOrUsageCode;
        }
        // Run!
        List<Object> nonOptionsCopy = new ArrayList<Object>(nonOptions);
        String commandName = (String) nonOptionsCopy.remove(0);
        String[] commandArgs = nonOptionsCopy.toArray(new String[0]);
        // Find command
        Command command = CommandFactory.getInstance(commandName);
        if (command == null) {
            return showErrorAndExit("Given command is unknown: " + commandName);
        }
        // Potentially show help
        if (options.has(optionHelp)) {
            return showCommandHelpAndExit(commandName);
        }
        // Pre-init operations
        initLocalDir(options, optionLocalDir);
        int configInitCode = initConfigIfRequired(command.getRequiredCommandScope(), localDir);
        if (configInitCode != 0) {
            return configInitCode;
        }
        initLogOption(options, optionLog, optionLogLevel, optionLogPrint, optionDebug);
        // Init command
        return runCommand(command, commandName, commandArgs);
    } catch (Exception e) {
        logger.log(Level.SEVERE, "Exception while initializing or running command.", e);
        return showErrorAndExit(e.getMessage());
    }
}
Also used : ArrayList(java.util.ArrayList) OptionParser(joptsimple.OptionParser) ConfigException(org.syncany.config.ConfigException) IOException(java.io.IOException) OptionSet(joptsimple.OptionSet) File(java.io.File)

Example 13 with OptionSet

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

use of joptsimple.OptionSet in project syncany by syncany.

the class DebugCommand method execute.

@Override
public int execute(String[] operationArgs) throws Exception {
    OptionParser parser = new OptionParser();
    OptionSet options = parser.parse(operationArgs);
    // Files
    List<?> nonOptionArgs = options.nonOptionArguments();
    if (nonOptionArgs.size() > 0) {
        String debugCommand = nonOptionArgs.get(0).toString();
        List<?> newNonOptionArgs = nonOptionArgs.subList(1, nonOptionArgs.size());
        if ("decrypt".equals(debugCommand)) {
            runDebugCommand(newNonOptionArgs);
        }
    }
    throw new Exception("Invalid syntax. No command given or command unknown.");
}
Also used : OptionSet(joptsimple.OptionSet) OptionParser(joptsimple.OptionParser)

Example 15 with OptionSet

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

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