use of joptsimple.OptionSet in project syncany by syncany.
the class GenlinkCommand method parseOptions.
@Override
public GenlinkOperationOptions parseOptions(String[] operationArgs) {
GenlinkOperationOptions operationOptions = new GenlinkOperationOptions();
OptionParser parser = new OptionParser();
OptionSpec<Void> optionMachineReadable = parser.acceptsAll(asList("m", "machine-readable"));
OptionSpec<Void> optionShort = parser.acceptsAll(asList("s", "short"));
parser.allowsUnrecognizedOptions();
OptionSet options = parser.parse(operationArgs);
// --machine-readable, -m
machineReadableOutput = options.has(optionMachineReadable);
// --short, -s
operationOptions.setShortUrl(options.has(optionShort));
return operationOptions;
}
use of joptsimple.OptionSet in project syncany by syncany.
the class LogCommand method parseOptions.
@Override
public LogOperationOptions parseOptions(String[] operationArgs) throws Exception {
LogOperationOptions operationOptions = new LogOperationOptions();
OptionParser parser = new OptionParser();
parser.allowsUnrecognizedOptions();
OptionSpec<Integer> optionMaxDatabaseVersionCountStr = parser.acceptsAll(asList("n", "database-count")).withRequiredArg().ofType(Integer.class);
OptionSpec<Integer> optionStartDatabaseVersionIndexStr = parser.acceptsAll(asList("s", "database-start")).withRequiredArg().ofType(Integer.class);
OptionSpec<Integer> optionMaxFileHistoryCountStr = parser.acceptsAll(asList("f", "file-count")).withRequiredArg().ofType(Integer.class);
OptionSpec<Void> optionExcludeEmpty = parser.acceptsAll(asList("x", "exclude-empty"));
OptionSet options = parser.parse(operationArgs);
// -x, --exclude-empty
excludeEmpty = options.has(optionExcludeEmpty);
// -n, --database-count=..
if (options.has(optionMaxDatabaseVersionCountStr)) {
operationOptions.setMaxDatabaseVersionCount(options.valueOf(optionMaxDatabaseVersionCountStr));
}
// -s, --database-start=..
if (options.has(optionStartDatabaseVersionIndexStr)) {
operationOptions.setStartDatabaseVersionIndex(options.valueOf(optionStartDatabaseVersionIndexStr));
}
// -f, --file-count=..
if (options.has(optionMaxFileHistoryCountStr)) {
operationOptions.setMaxFileHistoryCount(options.valueOf(optionMaxFileHistoryCountStr));
}
return operationOptions;
}
use of joptsimple.OptionSet in project syncany by syncany.
the class PluginCommand method parseOptions.
@Override
public PluginOperationOptions parseOptions(String[] operationArgs) throws Exception {
PluginOperationOptions operationOptions = new PluginOperationOptions();
OptionParser parser = new OptionParser();
OptionSpec<Void> optionLocal = parser.acceptsAll(asList("L", "local-only"));
OptionSpec<Void> optionRemote = parser.acceptsAll(asList("R", "remote-only"));
OptionSpec<Void> optionSnapshots = parser.acceptsAll(asList("s", "snapshot", "snapshots"));
OptionSpec<Void> optionMinimalOutput = parser.acceptsAll(asList("m", "minimal-output"));
OptionSpec<String> optionApiEndpoint = parser.acceptsAll(asList("a", "api-endpoint")).withRequiredArg();
OptionSet options = parser.parse(operationArgs);
// Files
List<?> nonOptionArgs = options.nonOptionArguments();
if (nonOptionArgs.size() == 0) {
throw new Exception("Invalid syntax, please specify an action (list, install, remove, update).");
}
// <action>
String actionStr = nonOptionArgs.get(0).toString();
PluginOperationAction action = parsePluginAction(actionStr);
operationOptions.setAction(action);
// --minimal-output
minimalOutput = options.has(optionMinimalOutput);
// --snapshots
operationOptions.setSnapshots(options.has(optionSnapshots));
// --api-endpoint
if (options.has(optionApiEndpoint)) {
operationOptions.setApiEndpoint(options.valueOf(optionApiEndpoint));
}
// install|remove <plugin-id>
if (action == PluginOperationAction.INSTALL || action == PluginOperationAction.REMOVE) {
if (nonOptionArgs.size() != 2) {
throw new Exception("Invalid syntax, please specify a plugin ID.");
}
// <plugin-id>
String pluginId = nonOptionArgs.get(1).toString();
operationOptions.setPluginId(pluginId);
} else // --local-only, --remote-only
if (action == PluginOperationAction.LIST) {
if (options.has(optionLocal)) {
operationOptions.setListMode(PluginListMode.LOCAL);
} else if (options.has(optionRemote)) {
operationOptions.setListMode(PluginListMode.REMOTE);
} else {
operationOptions.setListMode(PluginListMode.ALL);
}
// <plugin-id> (optional in 'list' or 'update')
if (nonOptionArgs.size() == 2) {
String pluginId = nonOptionArgs.get(1).toString();
operationOptions.setPluginId(pluginId);
}
} else if (action == PluginOperationAction.UPDATE && nonOptionArgs.size() == 2) {
String pluginId = nonOptionArgs.get(1).toString();
operationOptions.setPluginId(pluginId);
}
return operationOptions;
}
use of joptsimple.OptionSet in project syncany by syncany.
the class StatusCommand method parseOptions.
@Override
public StatusOperationOptions parseOptions(String[] operationArgs) throws Exception {
StatusOperationOptions operationOptions = new StatusOperationOptions();
OptionParser parser = new OptionParser();
parser.allowsUnrecognizedOptions();
OptionSpec<Void> optionForceChecksum = parser.acceptsAll(asList("f", "force-checksum"));
OptionSpec<Void> optionNoDeleteUpload = parser.acceptsAll(asList("D", "no-delete"));
OptionSet options = parser.parse(operationArgs);
// --force-checksum
operationOptions.setForceChecksum(options.has(optionForceChecksum));
// -D, --no-delete
operationOptions.setDelete(!options.has(optionNoDeleteUpload));
return operationOptions;
}
use of joptsimple.OptionSet in project gradle by gradle.
the class Main method main.
public static void main(String[] args) throws IOException {
OptionParser parser = new OptionParser();
ArgumentAcceptingOptionSpec<String> projectFlag = parser.accepts("project-dir", "Gradle project directory").withRequiredArg();
ArgumentAcceptingOptionSpec<String> gradleInstallFlag = parser.accepts("gradle-install", "Gradle installation to run the build with").withRequiredArg();
OptionSpecBuilder sync = parser.accepts("sync", "Simulate Gradle project synchronization");
OptionSpecBuilder embeddedFlag = parser.accepts("embedded", "Run build in-process");
OptionSet options = parser.parse(args);
if (!options.has(projectFlag)) {
System.out.println("No project directory specified.");
System.out.println();
parser.printHelpOn(System.out);
return;
}
File buildDir = new File(options.valueOf(projectFlag));
File gradleInstallDir = options.hasArgument(gradleInstallFlag) ? new File(options.valueOf(gradleInstallFlag)) : null;
boolean embedded = options.hasArgument(embeddedFlag);
boolean hasSimulation = options.has(sync);
if (options.has(sync) || hasSimulation) {
// defaults to 'sync', which is the only mode right now, hence the weird test above
fetch(buildDir, gradleInstallDir, embedded);
}
System.exit(0);
}
Aggregations