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;
}
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());
}
}
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;
}
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.");
}
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;
}
Aggregations