Search in sources :

Example 76 with OptionParser

use of joptsimple.OptionParser in project spring-framework by spring-projects.

the class JOptCommandLinePropertySourceTests method withDottedOptionName.

@Test
public void withDottedOptionName() {
    OptionParser parser = new OptionParser();
    parser.accepts("spring.profiles.active").withRequiredArg();
    OptionSet options = parser.parse("--spring.profiles.active=p1");
    CommandLinePropertySource<?> ps = new JOptCommandLinePropertySource(options);
    assertThat(ps.getProperty("spring.profiles.active"), equalTo("p1"));
}
Also used : OptionSet(joptsimple.OptionSet) OptionParser(joptsimple.OptionParser) Test(org.junit.Test)

Example 77 with OptionParser

use of joptsimple.OptionParser in project syncany by syncany.

the class LsCommand method parseOptions.

@Override
public LsOperationOptions parseOptions(String[] operationArgs) throws Exception {
    LsOperationOptions operationOptions = new LsOperationOptions();
    OptionParser parser = new OptionParser();
    parser.allowsUnrecognizedOptions();
    OptionSpec<String> optionDateStr = parser.acceptsAll(asList("D", "date")).withRequiredArg();
    OptionSpec<Void> optionRecursive = parser.acceptsAll(asList("r", "recursive"));
    OptionSpec<String> optionFileTypes = parser.acceptsAll(asList("t", "types")).withRequiredArg();
    OptionSpec<Void> optionLongChecksums = parser.acceptsAll(asList("f", "full-checksums"));
    OptionSpec<Void> optionWithVersions = parser.acceptsAll(asList("V", "versions"));
    OptionSpec<Void> optionGroupedVersions = parser.acceptsAll(asList("g", "group"));
    OptionSpec<Void> optionFileHistoryId = parser.acceptsAll(asList("H", "file-history"));
    OptionSpec<Void> optionDeleted = parser.acceptsAll(asList("q", "deleted"));
    OptionSet options = parser.parse(operationArgs);
    // --date=..
    if (options.has(optionDateStr)) {
        Date logViewDate = parseDateOption(options.valueOf(optionDateStr));
        operationOptions.setDate(logViewDate);
    }
    // --recursive
    operationOptions.setRecursive(options.has(optionRecursive));
    // --types=[tds]
    if (options.has(optionFileTypes)) {
        String fileTypesStr = options.valueOf(optionFileTypes).toLowerCase();
        HashSet<FileType> fileTypes = new HashSet<>();
        if (fileTypesStr.contains("f")) {
            fileTypes.add(FileType.FILE);
        }
        if (fileTypesStr.contains("d")) {
            fileTypes.add(FileType.FOLDER);
        }
        if (fileTypesStr.contains("s")) {
            fileTypes.add(FileType.SYMLINK);
        }
        operationOptions.setFileTypes(fileTypes);
    }
    // --versions
    fetchHistories = options.has(optionWithVersions) || options.has(optionFileHistoryId);
    operationOptions.setFetchHistories(fetchHistories);
    // --file-history
    operationOptions.setFileHistoryId(options.has(optionFileHistoryId));
    // --long-checksums (display option)
    checksumLength = (options.has(optionLongChecksums)) ? CHECKSUM_LENGTH_LONG : CHECKSUM_LENGTH_SHORT;
    // --group (display option)
    groupedVersions = options.has(optionGroupedVersions);
    // --deleted
    operationOptions.setDeleted(options.has(optionDeleted));
    // <path-expr>
    List<?> nonOptionArgs = options.nonOptionArguments();
    if (nonOptionArgs.size() > 0) {
        operationOptions.setPathExpression(nonOptionArgs.get(0).toString());
    }
    return operationOptions;
}
Also used : FileType(org.syncany.database.FileVersion.FileType) LsOperationOptions(org.syncany.operations.ls.LsOperationOptions) OptionSet(joptsimple.OptionSet) OptionParser(joptsimple.OptionParser) Date(java.util.Date) HashSet(java.util.HashSet)

Example 78 with OptionParser

use of joptsimple.OptionParser in project syncany by syncany.

the class RestoreCommand method parseOptions.

@Override
public RestoreOperationOptions parseOptions(String[] operationArgs) throws Exception {
    RestoreOperationOptions operationOptions = new RestoreOperationOptions();
    OptionParser parser = new OptionParser();
    parser.allowsUnrecognizedOptions();
    OptionSpec<Integer> optionRevision = parser.acceptsAll(asList("r", "revision")).withRequiredArg().ofType(Integer.class);
    OptionSpec<String> optionTarget = parser.acceptsAll(asList("t", "target")).withRequiredArg().ofType(String.class);
    OptionSet options = parser.parse(operationArgs);
    // --revision=<n>
    if (options.has(optionRevision)) {
        operationOptions.setFileVersion(options.valueOf(optionRevision));
    }
    // --target=<file>
    if (options.has(optionTarget)) {
        operationOptions.setRelativeTargetPath(options.valueOf(optionTarget));
    }
    // <file-history-id>
    List<?> nonOptionArgs = options.nonOptionArguments();
    if (nonOptionArgs.size() != 1) {
        throw new Exception("Invalid Syntax: File history ID must be specified.");
    }
    FileHistoryId restoreFileHistory = FileHistoryId.parseFileId(nonOptionArgs.get(0).toString());
    operationOptions.setFileHistoryId(restoreFileHistory);
    return operationOptions;
}
Also used : RestoreOperationOptions(org.syncany.operations.restore.RestoreOperationOptions) FileHistoryId(org.syncany.database.PartialFileHistory.FileHistoryId) OptionSet(joptsimple.OptionSet) OptionParser(joptsimple.OptionParser)

Example 79 with OptionParser

use of joptsimple.OptionParser in project syncany by syncany.

the class DaemonCommand method parseOptions.

@Override
public DaemonOperationOptions parseOptions(String[] operationArgs) throws Exception {
    DaemonOperationOptions operationOptions = new DaemonOperationOptions();
    OptionParser parser = new OptionParser();
    OptionSet options = parser.parse(operationArgs);
    // Files
    List<?> nonOptionArgs = options.nonOptionArguments();
    if (nonOptionArgs.size() == 0) {
        throw new Exception("Invalid syntax, no action given (start, stop, reload, restart, status, force-stop, list, add, remove).");
    }
    // <action>
    String actionStr = nonOptionArgs.get(0).toString();
    action = parseDaemonAction(actionStr);
    operationOptions.setAction(action);
    // add|remove (<folder-path> ...)
    if (action == DaemonAction.ADD || action == DaemonAction.REMOVE) {
        if (nonOptionArgs.size() < 2) {
            throw new Exception("Invalid syntax, please specify a folder path.");
        }
        // <folder-path> ...
        List<String> watchRoots = new ArrayList<>();
        for (int i = 1; i < nonOptionArgs.size(); i++) {
            watchRoots.add(nonOptionArgs.get(i).toString());
        }
        operationOptions.setWatchRoots(watchRoots);
    }
    return operationOptions;
}
Also used : ArrayList(java.util.ArrayList) OptionSet(joptsimple.OptionSet) DaemonOperationOptions(org.syncany.operations.daemon.DaemonOperationOptions) OptionParser(joptsimple.OptionParser)

Example 80 with OptionParser

use of joptsimple.OptionParser in project syncany by syncany.

the class InitCommand method parseOptions.

@Override
public InitOperationOptions parseOptions(String[] operationArguments) throws Exception {
    InitOperationOptions operationOptions = new InitOperationOptions();
    OptionParser parser = new OptionParser();
    OptionSpec<Void> optionNoCreateTarget = parser.acceptsAll(asList("T", "no-create-target"));
    OptionSpec<Void> optionAdvanced = parser.acceptsAll(asList("a", "advanced"));
    OptionSpec<Void> optionNoCompression = parser.acceptsAll(asList("G", "no-compression"));
    OptionSpec<Void> optionNoEncryption = parser.acceptsAll(asList("E", "no-encryption"));
    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<Void> optionShortUrl = parser.acceptsAll(asList("s", "short"));
    OptionSpec<Void> optionHeadlessMode = parser.acceptsAll(asList("l", "headless"));
    OptionSpec<String> optionPassword = parser.acceptsAll(asList("password")).withRequiredArg();
    OptionSet options = parser.parse(operationArguments);
    // Set interactivity mode
    isInteractive = !options.has(optionPlugin);
    // Set headless mode
    isHeadless = options.has(optionHeadlessMode);
    // Ask or set transfer settings
    TransferSettings transferSettings = createTransferSettingsFromOptions(options, optionPlugin, optionPluginOpts);
    // Some misc settings
    boolean createTargetPath = !options.has(optionNoCreateTarget);
    boolean advancedModeEnabled = options.has(optionAdvanced);
    boolean encryptionEnabled = !options.has(optionNoEncryption);
    boolean compressionEnabled = !options.has(optionNoCompression);
    // Cipher specs: --no-encryption, --advanced
    List<CipherSpec> cipherSpecs = getCipherSpecs(encryptionEnabled, advancedModeEnabled);
    // Compression: --no-compression
    // DefaultRepoTOFactory also creates default chunkers
    RepoTOFactory repoTOFactory = new DefaultRepoTOFactory(compressionEnabled, cipherSpecs);
    // Genlink options: --short
    GenlinkOperationOptions genlinkOptions = new GenlinkOperationOptions();
    genlinkOptions.setShortUrl(options.has(optionShortUrl));
    // Set repo password
    String password = validateAndGetPassword(options, optionNoEncryption, optionPassword);
    operationOptions.setPassword(password);
    // Create configTO and repoTO
    ConfigTO configTO = createConfigTO(transferSettings);
    RepoTO repoTO = repoTOFactory.createRepoTO();
    operationOptions.setLocalDir(localDir);
    operationOptions.setConfigTO(configTO);
    operationOptions.setRepoTO(repoTO);
    operationOptions.setCreateTarget(createTargetPath);
    operationOptions.setEncryptionEnabled(encryptionEnabled);
    operationOptions.setCipherSpecs(cipherSpecs);
    operationOptions.setDaemon(options.has(optionAddDaemon));
    operationOptions.setGenlinkOptions(genlinkOptions);
    return operationOptions;
}
Also used : InitOperationOptions(org.syncany.operations.init.InitOperationOptions) DefaultRepoTOFactory(org.syncany.config.to.DefaultRepoTOFactory) TransferSettings(org.syncany.plugins.transfer.TransferSettings) GenlinkOperationOptions(org.syncany.operations.init.GenlinkOperationOptions) OptionParser(joptsimple.OptionParser) DefaultRepoTOFactory(org.syncany.config.to.DefaultRepoTOFactory) RepoTOFactory(org.syncany.config.to.RepoTOFactory) CipherSpec(org.syncany.crypto.CipherSpec) ConfigTO(org.syncany.config.to.ConfigTO) OptionSet(joptsimple.OptionSet) RepoTO(org.syncany.config.to.RepoTO)

Aggregations

OptionParser (joptsimple.OptionParser)118 OptionSet (joptsimple.OptionSet)91 File (java.io.File)35 IOException (java.io.IOException)15 OptionException (joptsimple.OptionException)14 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