Search in sources :

Example 1 with FileType

use of org.syncany.database.FileVersion.FileType 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)

Aggregations

Date (java.util.Date)1 HashSet (java.util.HashSet)1 OptionParser (joptsimple.OptionParser)1 OptionSet (joptsimple.OptionSet)1 FileType (org.syncany.database.FileVersion.FileType)1 LsOperationOptions (org.syncany.operations.ls.LsOperationOptions)1