use of joptsimple.OptionSet in project syncany by syncany.
the class UpCommand method parseOptions.
@Override
public UpOperationOptions parseOptions(String[] operationArgs) throws Exception {
UpOperationOptions operationOptions = new UpOperationOptions();
OptionParser parser = new OptionParser();
parser.allowsUnrecognizedOptions();
OptionSpec<Void> optionForceUpload = parser.acceptsAll(asList("F", "force-upload"));
OptionSpec<Void> optionNoResumeUpload = parser.acceptsAll(asList("R", "no-resume"));
OptionSet options = parser.parse(operationArgs);
// status [<args>]
operationOptions.setStatusOptions(parseStatusOptions(operationArgs));
// -F, --force-upload
operationOptions.setForceUploadEnabled(options.has(optionForceUpload));
// -R, --no-resume
operationOptions.setResume(!options.has(optionNoResumeUpload));
return operationOptions;
}
use of joptsimple.OptionSet in project syncany by syncany.
the class UpdateCommand method parseOptions.
@Override
public UpdateOperationOptions parseOptions(String[] operationArgs) throws Exception {
UpdateOperationOptions operationOptions = new UpdateOperationOptions();
OptionParser parser = new OptionParser();
OptionSpec<Void> optionSnapshots = parser.acceptsAll(asList("s", "snapshot", "snapshots"));
OptionSpec<String> optionApiEndpoint = parser.acceptsAll(asList("a", "api-endpoint")).withRequiredArg();
OptionSet options = parser.parse(operationArgs);
// Action
List<?> nonOptionArgs = options.nonOptionArguments();
if (nonOptionArgs.size() == 0) {
throw new Exception("Invalid syntax, please specify an action (check).");
}
// <action>
String actionStr = nonOptionArgs.get(0).toString();
UpdateOperationAction action = parseAction(actionStr);
operationOptions.setAction(action);
// --snapshots
operationOptions.setSnapshots(options.has(optionSnapshots));
// --api-endpoint
if (options.has(optionApiEndpoint)) {
operationOptions.setApiEndpoint(options.valueOf(optionApiEndpoint));
}
return operationOptions;
}
use of joptsimple.OptionSet in project syncany by syncany.
the class WatchCommand method parseOptions.
@Override
public WatchOperationOptions parseOptions(String[] operationArgs) throws Exception {
WatchOperationOptions operationOptions = new WatchOperationOptions();
OptionParser parser = new OptionParser();
OptionSpec<Integer> optionInterval = parser.acceptsAll(asList("i", "interval")).withRequiredArg().ofType(Integer.class);
OptionSpec<Void> optionNoAnnouncements = parser.acceptsAll(asList("N", "no-announcements"));
OptionSpec<String> optionAnnouncements = parser.acceptsAll(asList("a", "announce")).withRequiredArg();
OptionSpec<Void> optionNoWatcher = parser.acceptsAll(asList("W", "no-watcher"));
OptionSpec<Integer> optionSettleDelay = parser.acceptsAll(asList("s", "delay")).withRequiredArg().ofType(Integer.class);
OptionSet options = parser.parse(operationArgs);
// --interval
if (options.has(optionInterval)) {
operationOptions.setInterval(options.valueOf(optionInterval) * 1000);
}
// Conflicting options: --no-announcements and --announce=<..>
if (options.has(optionNoAnnouncements) && options.has(optionAnnouncements)) {
throw new Exception("Options --no-announcements and --announce in conflict with one another.");
}
// --no-announcements
if (options.has(optionNoAnnouncements)) {
operationOptions.setAnnouncements(false);
}
// --announce=<host>:<port>
if (options.has(optionAnnouncements)) {
operationOptions.setAnnouncements(true);
String announcementsStr = options.valueOf(optionAnnouncements);
Matcher matcher = ANNOUNCEMENTS_PATTERN.matcher(announcementsStr);
if (!matcher.matches()) {
throw new Exception("Invalid argument for --announcements, expected pattern: " + ANNOUNCEMENTS_PATTERN.pattern());
}
String announcementsHost = matcher.group(ANNOUNCEMENTS_PATTERN_GROUP_HOST);
int announcementsPort = Integer.parseInt(matcher.group(ANNOUNCEMENTS_PATTERN_GROUP_PORT));
operationOptions.setAnnouncementsHost(announcementsHost);
operationOptions.setAnnouncementsPort(announcementsPort);
}
// --delay=<sec>
if (options.has(optionSettleDelay)) {
operationOptions.setSettleDelay(options.valueOf(optionSettleDelay) * 1000);
}
// --no-watcher
if (options.has(optionNoWatcher)) {
operationOptions.setWatcher(false);
}
return operationOptions;
}
use of joptsimple.OptionSet in project voldemort by voldemort.
the class AdminTest method main.
@SuppressWarnings("unchecked")
public static void main(String[] args) throws Exception {
OptionParser parser = new OptionParser();
parser.accepts("native", "use native admin client");
parser.accepts("f", "execute fetch operation");
parser.accepts("fu", "fetch and update").withRequiredArg().ofType(Integer.class);
parser.accepts("n", "node id").withRequiredArg().ofType(Integer.class).withValuesSeparatedBy(',');
parser.accepts("p", "partition id").withRequiredArg().ofType(Integer.class).withValuesSeparatedBy(',');
OptionSet options = parser.parse(args);
List<String> nonOptions = (List<String>) options.nonOptionArguments();
if (args.length < 2) {
System.out.println(usageStr);
return;
}
String bootstrapUrl = nonOptions.get(0);
String storeName = nonOptions.get(1);
if (!options.has("p") && !options.has("n")) {
printUsage(System.err, parser, "One or more node and/or one or more partition has" + " to be specified");
}
AdminTest adminTest;
adminTest = new AdminTest(bootstrapUrl, storeName);
SetMultimap<Integer, Integer> nodePartitions = adminTest.getNodePartitions(options.has("n") ? options.valuesOf("n") : null, options.has("p") ? options.valuesOf("p") : null);
if (options.has("f"))
adminTest.testFetch(nodePartitions);
if (options.has("fu"))
adminTest.testFetchAndUpdate(nodePartitions, (Integer) options.valueOf("fu"));
}
use of joptsimple.OptionSet in project voldemort by voldemort.
the class ClusterForkLiftTool method main.
/**
* @param args
*/
public static void main(String[] args) throws Exception {
OptionParser parser = null;
OptionSet options = null;
try {
parser = getParser();
options = parser.parse(args);
} catch (Exception oe) {
logger.error("Exception processing command line options", oe);
parser.printHelpOn(System.out);
return;
}
/* validate options */
if (options.has("help")) {
parser.printHelpOn(System.out);
return;
}
if (!options.has("src-url") || !options.has("dst-url") || !options.has("stores")) {
logger.error("'src-url' 'dst-url' and 'stores' are mandatory parameters ");
parser.printHelpOn(System.out);
return;
}
String srcBootstrapUrl = (String) options.valueOf("src-url");
String dstBootstrapUrl = (String) options.valueOf("dst-url");
int maxPutsPerSecond = DEFAULT_MAX_PUTS_PER_SEC;
if (options.has("max-puts-per-second"))
maxPutsPerSecond = (Integer) options.valueOf("max-puts-per-second");
List<String> storesList = null;
if (options.has("stores")) {
storesList = new ArrayList<String>((List<String>) options.valuesOf("stores"));
}
List<Integer> partitions = null;
if (options.has("partitions")) {
partitions = (List<Integer>) options.valuesOf("partitions");
}
int partitionParallelism = DEFAULT_PARTITION_PARALLELISM;
if (options.has("parallelism")) {
partitionParallelism = (Integer) options.valueOf("parallelism");
}
int progressOps = DEFAULT_PROGRESS_PERIOD_OPS;
if (options.has("progress-period-ops")) {
progressOps = (Integer) options.valueOf("progress-period-ops");
}
ForkLiftTaskMode mode = ForkLiftTaskMode.primary_resolution;
if (options.has("mode")) {
mode = ForkLiftTaskMode.valueOf((String) options.valueOf("mode"));
if (mode == null)
mode = ForkLiftTaskMode.primary_resolution;
}
Boolean overwrite = extractBoolOption(options, OVERWRITE_OPTION);
boolean ignoreSchemaMismatch = extractBoolOption(options, IGNORE_SCHEMA_MISMATCH);
ClusterForkLiftTool forkLiftTool = new ClusterForkLiftTool(srcBootstrapUrl, dstBootstrapUrl, overwrite, ignoreSchemaMismatch, maxPutsPerSecond, partitionParallelism, progressOps, storesList, partitions, mode);
forkLiftTool.run();
// TODO cleanly shut down the hanging threadpool
System.exit(0);
}
Aggregations