use of joptsimple.OptionSpec in project jackrabbit-oak by apache.
the class UnlockUpgradeCommand method execute.
@Override
public void execute(String... args) throws Exception {
OptionParser parser = new OptionParser();
// RDB specific options
OptionSpec<String> rdbjdbcuser = parser.accepts("rdbjdbcuser", "RDB JDBC user").withOptionalArg().defaultsTo("");
OptionSpec<String> rdbjdbcpasswd = parser.accepts("rdbjdbcpasswd", "RDB JDBC password").withOptionalArg().defaultsTo("");
OptionSpec<String> nonOption = parser.nonOptions("unlockUpgrade {<jdbc-uri> | <mongodb-uri>}");
OptionSpec help = parser.acceptsAll(asList("h", "?", "help"), "show help").forHelp();
OptionSet options = parser.parse(args);
List<String> nonOptions = nonOption.values(options);
if (options.has(help)) {
parser.printHelpOn(System.out);
return;
}
if (nonOptions.isEmpty()) {
parser.printHelpOn(System.err);
return;
}
DocumentStore store = null;
try {
String uri = nonOptions.get(0);
if (uri.startsWith(MONGODB_PREFIX)) {
MongoClientURI clientURI = new MongoClientURI(uri);
if (clientURI.getDatabase() == null) {
System.err.println("Database missing in MongoDB URI: " + clientURI.getURI());
} else {
MongoConnection mongo = new MongoConnection(clientURI.getURI());
store = new MongoDocumentStore(mongo.getMongoClient(), mongo.getDBName(), new MongoDocumentNodeStoreBuilder());
}
} else if (uri.startsWith("jdbc")) {
DataSource ds = RDBDataSourceFactory.forJdbcUrl(uri, rdbjdbcuser.value(options), rdbjdbcpasswd.value(options));
store = new RDBDocumentStore(ds, new DocumentNodeStoreBuilder());
} else {
System.err.println("Unrecognized URI: " + uri);
}
if (store != null && VERSION.writeTo(store)) {
System.out.println("Format version set to " + VERSION);
}
} catch (DocumentStoreException e) {
System.err.println(e.getMessage());
} finally {
if (store != null) {
store.dispose();
}
}
}
use of joptsimple.OptionSpec 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);
int code = 0;
try (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);
if (!scriptArgs.isEmpty()) {
if (!options.has(shell)) {
Preferences.verbosity = IO.Verbosity.QUIET;
}
code = console.execute(scriptArgs);
}
if (scriptArgs.isEmpty() || options.has(shell)) {
code = console.run();
}
}
System.exit(code);
}
use of joptsimple.OptionSpec in project jackrabbit-oak by apache.
the class OakHelpFormatter method getOptionNames.
private static Set<String> getOptionNames(OptionsBean bean) {
Set<String> names = new HashSet<>();
try {
for (Field field : bean.getClass().getDeclaredFields()) {
if (OptionSpec.class.isAssignableFrom(field.getType())) {
field.setAccessible(true);
OptionSpec spec = (OptionSpec) field.get(bean);
names.addAll(spec.options());
}
}
} catch (Exception e) {
throw new RuntimeException(e);
}
return names;
}
use of joptsimple.OptionSpec in project hazelcast-simulator by hazelcast.
the class CliUtils method initOptionsWithHelp.
public static OptionSet initOptionsWithHelp(OptionParser parser, String help, String[] args) {
try {
OptionSpec helpSpec = parser.accepts("help", "Shows the help.").forHelp();
OptionSet options = parser.parse(args);
if (options.has(helpSpec)) {
if (help != null) {
printHelp(help);
}
printHelpAndExit(parser, System.out);
}
return options;
} catch (OptionException e) {
throw new CommandLineExitException(e.getMessage() + ". Use --help to get overview of the help options.");
}
}
use of joptsimple.OptionSpec in project jopt-simple by jopt-simple.
the class ExportOptionsTest method asProperties.
private static Properties asProperties(OptionSet options, String prefix) {
Properties properties = new Properties();
for (Entry<OptionSpec<?>, List<?>> entry : options.asMap().entrySet()) {
OptionSpec<?> spec = entry.getKey();
properties.setProperty(asPropertyKey(prefix, spec), asPropertyValue(entry.getValue(), options.has(spec)));
}
return properties;
}
Aggregations