return 0;
}
@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> optionNoDatabaseMerge = parser.acceptsAll(asList("M", "no-database-merge"));
OptionSpec<Void> optionNoOldVersionRemoval = parser.acceptsAll(asList("V", "no-version-removal"));
OptionSpec<Void> optionNoRemoveTempFiles = parser.acceptsAll(asList("T", "no-temp-removal"));
OptionSpec<Integer> optionKeepVersions = parser.acceptsAll(asList("k", "keep-versions")).withRequiredArg().ofType(Integer.class);
OptionSpec<String> optionSecondsBetweenCleanups = parser.acceptsAll(asList("t", "time-between-cleanups")).withRequiredArg()
.ofType(String.class);
OptionSpec<Integer> optionMaxDatabaseFiles = parser.acceptsAll(asList("x", "max-database-files")).withRequiredArg().ofType(Integer.class);
OptionSet options = parser.parse(operationArgs);
// -F, --force
operationOptions.setForce(options.has(optionForce));
// -M, --no-database-merge
operationOptions.setMergeRemoteFiles(!options.has(optionNoDatabaseMerge));
// -V, --no-version-removal
operationOptions.setRemoveOldVersions(!options.has(optionNoOldVersionRemoval));
// -T, --no-temp-removal
operationOptions.setRemoveUnreferencedTemporaryFiles(!options.has(optionNoRemoveTempFiles));
// -k=<count>, --keep-versions=<count>
if (options.has(optionKeepVersions)) {
int keepVersionCount = options.valueOf(optionKeepVersions);
if (keepVersionCount < 1) {
throw new Exception("Invalid value for --keep-versions=" + keepVersionCount + "; must be >= 1");
}
operationOptions.setKeepVersionsCount(options.valueOf(optionKeepVersions));
}
// -t=<count>, --time-between-cleanups=<count>
if (options.has(optionSecondsBetweenCleanups)) {
long secondsBetweenCleanups = CommandLineUtil.parseTimePeriod(options.valueOf(optionSecondsBetweenCleanups));
if (secondsBetweenCleanups < 0) {
throw new Exception("Invalid value for --time-between-cleanups=" + secondsBetweenCleanups + "; must be >= 0");
}
operationOptions.setMinSecondsBetweenCleanups(secondsBetweenCleanups);
}
// -d=<count>, --max-database-files=<count>
if (options.has(optionMaxDatabaseFiles)) {
int maxDatabaseFiles = options.valueOf(optionMaxDatabaseFiles);
if (maxDatabaseFiles < 1) {
throw new Exception("Invalid value for --max-database-files=" + maxDatabaseFiles + "; must be >= 1");
}
operationOptions.setMaxDatabaseFiles(maxDatabaseFiles);
}
// Parse 'status' options
operationOptions.setStatusOptions(parseStatusOptions(operationArgs));
// Does this configuration make sense
boolean nothingToDo = !operationOptions.isMergeRemoteFiles() && operationOptions.isRemoveOldVersions();
if (nothingToDo) {
throw new Exception("Invalid parameter configuration: -M and -V cannot be set together. Nothing to do.");
}