Search in sources :

Example 1 with UpdateOperationAction

use of org.syncany.operations.update.UpdateOperationAction 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;
}
Also used : UpdateOperationOptions(org.syncany.operations.update.UpdateOperationOptions) UpdateOperationAction(org.syncany.operations.update.UpdateOperationAction) OptionSet(joptsimple.OptionSet) OptionParser(joptsimple.OptionParser)

Aggregations

OptionParser (joptsimple.OptionParser)1 OptionSet (joptsimple.OptionSet)1 UpdateOperationAction (org.syncany.operations.update.UpdateOperationAction)1 UpdateOperationOptions (org.syncany.operations.update.UpdateOperationOptions)1