use of joptsimple.OptionParser in project spring-framework by spring-projects.
the class JOptCommandLinePropertySourceTests method withDottedOptionName.
@Test
public void withDottedOptionName() {
OptionParser parser = new OptionParser();
parser.accepts("spring.profiles.active").withRequiredArg();
OptionSet options = parser.parse("--spring.profiles.active=p1");
CommandLinePropertySource<?> ps = new JOptCommandLinePropertySource(options);
assertThat(ps.getProperty("spring.profiles.active"), equalTo("p1"));
}
use of joptsimple.OptionParser in project syncany by syncany.
the class LsCommand method parseOptions.
@Override
public LsOperationOptions parseOptions(String[] operationArgs) throws Exception {
LsOperationOptions operationOptions = new LsOperationOptions();
OptionParser parser = new OptionParser();
parser.allowsUnrecognizedOptions();
OptionSpec<String> optionDateStr = parser.acceptsAll(asList("D", "date")).withRequiredArg();
OptionSpec<Void> optionRecursive = parser.acceptsAll(asList("r", "recursive"));
OptionSpec<String> optionFileTypes = parser.acceptsAll(asList("t", "types")).withRequiredArg();
OptionSpec<Void> optionLongChecksums = parser.acceptsAll(asList("f", "full-checksums"));
OptionSpec<Void> optionWithVersions = parser.acceptsAll(asList("V", "versions"));
OptionSpec<Void> optionGroupedVersions = parser.acceptsAll(asList("g", "group"));
OptionSpec<Void> optionFileHistoryId = parser.acceptsAll(asList("H", "file-history"));
OptionSpec<Void> optionDeleted = parser.acceptsAll(asList("q", "deleted"));
OptionSet options = parser.parse(operationArgs);
// --date=..
if (options.has(optionDateStr)) {
Date logViewDate = parseDateOption(options.valueOf(optionDateStr));
operationOptions.setDate(logViewDate);
}
// --recursive
operationOptions.setRecursive(options.has(optionRecursive));
// --types=[tds]
if (options.has(optionFileTypes)) {
String fileTypesStr = options.valueOf(optionFileTypes).toLowerCase();
HashSet<FileType> fileTypes = new HashSet<>();
if (fileTypesStr.contains("f")) {
fileTypes.add(FileType.FILE);
}
if (fileTypesStr.contains("d")) {
fileTypes.add(FileType.FOLDER);
}
if (fileTypesStr.contains("s")) {
fileTypes.add(FileType.SYMLINK);
}
operationOptions.setFileTypes(fileTypes);
}
// --versions
fetchHistories = options.has(optionWithVersions) || options.has(optionFileHistoryId);
operationOptions.setFetchHistories(fetchHistories);
// --file-history
operationOptions.setFileHistoryId(options.has(optionFileHistoryId));
// --long-checksums (display option)
checksumLength = (options.has(optionLongChecksums)) ? CHECKSUM_LENGTH_LONG : CHECKSUM_LENGTH_SHORT;
// --group (display option)
groupedVersions = options.has(optionGroupedVersions);
// --deleted
operationOptions.setDeleted(options.has(optionDeleted));
// <path-expr>
List<?> nonOptionArgs = options.nonOptionArguments();
if (nonOptionArgs.size() > 0) {
operationOptions.setPathExpression(nonOptionArgs.get(0).toString());
}
return operationOptions;
}
use of joptsimple.OptionParser in project syncany by syncany.
the class RestoreCommand method parseOptions.
@Override
public RestoreOperationOptions parseOptions(String[] operationArgs) throws Exception {
RestoreOperationOptions operationOptions = new RestoreOperationOptions();
OptionParser parser = new OptionParser();
parser.allowsUnrecognizedOptions();
OptionSpec<Integer> optionRevision = parser.acceptsAll(asList("r", "revision")).withRequiredArg().ofType(Integer.class);
OptionSpec<String> optionTarget = parser.acceptsAll(asList("t", "target")).withRequiredArg().ofType(String.class);
OptionSet options = parser.parse(operationArgs);
// --revision=<n>
if (options.has(optionRevision)) {
operationOptions.setFileVersion(options.valueOf(optionRevision));
}
// --target=<file>
if (options.has(optionTarget)) {
operationOptions.setRelativeTargetPath(options.valueOf(optionTarget));
}
// <file-history-id>
List<?> nonOptionArgs = options.nonOptionArguments();
if (nonOptionArgs.size() != 1) {
throw new Exception("Invalid Syntax: File history ID must be specified.");
}
FileHistoryId restoreFileHistory = FileHistoryId.parseFileId(nonOptionArgs.get(0).toString());
operationOptions.setFileHistoryId(restoreFileHistory);
return operationOptions;
}
use of joptsimple.OptionParser in project syncany by syncany.
the class DaemonCommand method parseOptions.
@Override
public DaemonOperationOptions parseOptions(String[] operationArgs) throws Exception {
DaemonOperationOptions operationOptions = new DaemonOperationOptions();
OptionParser parser = new OptionParser();
OptionSet options = parser.parse(operationArgs);
// Files
List<?> nonOptionArgs = options.nonOptionArguments();
if (nonOptionArgs.size() == 0) {
throw new Exception("Invalid syntax, no action given (start, stop, reload, restart, status, force-stop, list, add, remove).");
}
// <action>
String actionStr = nonOptionArgs.get(0).toString();
action = parseDaemonAction(actionStr);
operationOptions.setAction(action);
// add|remove (<folder-path> ...)
if (action == DaemonAction.ADD || action == DaemonAction.REMOVE) {
if (nonOptionArgs.size() < 2) {
throw new Exception("Invalid syntax, please specify a folder path.");
}
// <folder-path> ...
List<String> watchRoots = new ArrayList<>();
for (int i = 1; i < nonOptionArgs.size(); i++) {
watchRoots.add(nonOptionArgs.get(i).toString());
}
operationOptions.setWatchRoots(watchRoots);
}
return operationOptions;
}
use of joptsimple.OptionParser in project syncany by syncany.
the class InitCommand method parseOptions.
@Override
public InitOperationOptions parseOptions(String[] operationArguments) throws Exception {
InitOperationOptions operationOptions = new InitOperationOptions();
OptionParser parser = new OptionParser();
OptionSpec<Void> optionNoCreateTarget = parser.acceptsAll(asList("T", "no-create-target"));
OptionSpec<Void> optionAdvanced = parser.acceptsAll(asList("a", "advanced"));
OptionSpec<Void> optionNoCompression = parser.acceptsAll(asList("G", "no-compression"));
OptionSpec<Void> optionNoEncryption = parser.acceptsAll(asList("E", "no-encryption"));
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<Void> optionShortUrl = parser.acceptsAll(asList("s", "short"));
OptionSpec<Void> optionHeadlessMode = parser.acceptsAll(asList("l", "headless"));
OptionSpec<String> optionPassword = parser.acceptsAll(asList("password")).withRequiredArg();
OptionSet options = parser.parse(operationArguments);
// Set interactivity mode
isInteractive = !options.has(optionPlugin);
// Set headless mode
isHeadless = options.has(optionHeadlessMode);
// Ask or set transfer settings
TransferSettings transferSettings = createTransferSettingsFromOptions(options, optionPlugin, optionPluginOpts);
// Some misc settings
boolean createTargetPath = !options.has(optionNoCreateTarget);
boolean advancedModeEnabled = options.has(optionAdvanced);
boolean encryptionEnabled = !options.has(optionNoEncryption);
boolean compressionEnabled = !options.has(optionNoCompression);
// Cipher specs: --no-encryption, --advanced
List<CipherSpec> cipherSpecs = getCipherSpecs(encryptionEnabled, advancedModeEnabled);
// Compression: --no-compression
// DefaultRepoTOFactory also creates default chunkers
RepoTOFactory repoTOFactory = new DefaultRepoTOFactory(compressionEnabled, cipherSpecs);
// Genlink options: --short
GenlinkOperationOptions genlinkOptions = new GenlinkOperationOptions();
genlinkOptions.setShortUrl(options.has(optionShortUrl));
// Set repo password
String password = validateAndGetPassword(options, optionNoEncryption, optionPassword);
operationOptions.setPassword(password);
// Create configTO and repoTO
ConfigTO configTO = createConfigTO(transferSettings);
RepoTO repoTO = repoTOFactory.createRepoTO();
operationOptions.setLocalDir(localDir);
operationOptions.setConfigTO(configTO);
operationOptions.setRepoTO(repoTO);
operationOptions.setCreateTarget(createTargetPath);
operationOptions.setEncryptionEnabled(encryptionEnabled);
operationOptions.setCipherSpecs(cipherSpecs);
operationOptions.setDaemon(options.has(optionAddDaemon));
operationOptions.setGenlinkOptions(genlinkOptions);
return operationOptions;
}
Aggregations