use of joptsimple.OptionParser in project jackrabbit-oak by apache.
the class IndexCommand method execute.
@Override
public void execute(String... args) throws Exception {
OptionParser parser = new OptionParser();
opts = new Options();
opts.setCommandName(NAME);
opts.setSummary(summary);
opts.setConnectionString(CommonOptions.DEFAULT_CONNECTION_STRING);
opts.registerOptionsFactory(IndexOptions.FACTORY);
opts.parseAndConfigure(parser, args);
IndexOptions indexOpts = opts.getOptionBean(IndexOptions.class);
//Clean up before setting up NodeStore as the temp
//directory might be used by NodeStore for cache stuff like persistentCache
setupDirectories(indexOpts);
NodeStoreFixture fixture = NodeStoreFixtureProvider.create(opts);
try (Closer closer = Closer.create()) {
closer.register(fixture);
StatisticsProvider statisticsProvider = WhiteboardUtils.getService(fixture.getWhiteboard(), StatisticsProvider.class);
execute(fixture.getStore(), fixture.getBlobStore(), statisticsProvider, indexOpts, closer);
tellReportPaths();
}
}
use of joptsimple.OptionParser in project jackrabbit-oak by apache.
the class Console method main.
public static void main(String[] args) throws Exception {
OptionParser parser = new OptionParser();
OptionSpec quiet = parser.accepts("quiet", "be less chatty");
OptionSpec shell = parser.accepts("shell", "run the shell after executing files");
Options opts = new Options();
OptionSet options = opts.parseAndConfigure(parser, args);
NodeStoreFixture fixture = NodeStoreFixtureProvider.create(opts);
List<String> nonOptions = opts.getCommonOpts().getNonOptions();
List<String> scriptArgs = nonOptions.size() > 1 ? nonOptions.subList(1, nonOptions.size()) : Collections.emptyList();
IO io = new IO();
if (options.has(quiet)) {
io.setVerbosity(IO.Verbosity.QUIET);
}
if (!opts.getCommonOpts().isReadWrite()) {
io.out.println("Repository connected in read-only mode. Use '--read-write' for write operations");
}
GroovyConsole console = new GroovyConsole(ConsoleSession.create(fixture.getStore(), fixture.getWhiteboard()), new IO(), fixture);
int code = 0;
if (!scriptArgs.isEmpty()) {
code = console.execute(scriptArgs);
}
if (scriptArgs.isEmpty() || options.has(shell)) {
code = console.run();
}
System.exit(code);
}
use of joptsimple.OptionParser in project jackrabbit-oak by apache.
the class Utils method bootstrapDataStore.
@Nullable
public static GarbageCollectableBlobStore bootstrapDataStore(String[] args, Closer closer) throws IOException, RepositoryException {
OptionParser parser = new OptionParser();
parser.allowsUnrecognizedOptions();
ArgumentAcceptingOptionSpec<String> s3dsConfig = parser.accepts("s3ds", "S3DataStore config").withRequiredArg().ofType(String.class);
ArgumentAcceptingOptionSpec<String> fdsConfig = parser.accepts("fds", "FileDataStore config").withRequiredArg().ofType(String.class);
ArgumentAcceptingOptionSpec<String> azureBlobDSConfig = parser.accepts("azureblobds", "AzureBlobStorageDataStore config").withRequiredArg().ofType(String.class);
OptionSet options = parser.parse(args);
if (!options.has(s3dsConfig) && !options.has(fdsConfig) && !options.has(azureBlobDSConfig)) {
return null;
}
DataStore delegate;
if (options.has(s3dsConfig)) {
SharedS3DataStore s3ds = new SharedS3DataStore();
String cfgPath = s3dsConfig.value(options);
Properties props = loadAndTransformProps(cfgPath);
s3ds.setProperties(props);
File homeDir = Files.createTempDir();
closer.register(asCloseable(homeDir));
s3ds.init(homeDir.getAbsolutePath());
delegate = s3ds;
} else if (options.has(azureBlobDSConfig)) {
AzureDataStore azureds = new AzureDataStore();
String cfgPath = azureBlobDSConfig.value(options);
Properties props = loadAndTransformProps(cfgPath);
azureds.setProperties(props);
File homeDir = Files.createTempDir();
azureds.init(homeDir.getAbsolutePath());
closer.register(asCloseable(homeDir));
delegate = azureds;
} else {
delegate = new OakFileDataStore();
String cfgPath = fdsConfig.value(options);
Properties props = loadAndTransformProps(cfgPath);
populate(delegate, asMap(props), true);
delegate.init(null);
}
DataStoreBlobStore blobStore = new DataStoreBlobStore(delegate);
closer.register(Utils.asCloseable(blobStore));
return blobStore;
}
use of joptsimple.OptionParser in project jackrabbit-oak by apache.
the class OptionsTest method noArgs.
@Test
public void noArgs() throws Exception {
OptionParser parser = new OptionParser();
Options opts = new Options().withDisableSystemExit();
opts.parseAndConfigure(parser, new String[] {});
assertNotNull(opts.getCommonOpts());
}
use of joptsimple.OptionParser in project jackrabbit-oak by apache.
the class BlobStoreFixtureProviderTest method createFDSOptions.
private Options createFDSOptions(String... args) throws IOException {
OptionParser parser = new OptionParser();
Options opts = new Options().withDisableSystemExit();
opts.parseAndConfigure(parser, args);
return opts;
}
Aggregations