Search in sources :

Example 6 with OptionSpec

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();
        }
    }
}
Also used : OptionSpec(joptsimple.OptionSpec) DocumentStoreException(org.apache.jackrabbit.oak.plugins.document.DocumentStoreException) MongoClientURI(com.mongodb.MongoClientURI) OptionParser(joptsimple.OptionParser) MongoDocumentStore(org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentStore) DocumentNodeStoreBuilder(org.apache.jackrabbit.oak.plugins.document.DocumentNodeStoreBuilder) MongoDocumentNodeStoreBuilder(org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentNodeStoreBuilder) DataSource(javax.sql.DataSource) MongoDocumentNodeStoreBuilder(org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentNodeStoreBuilder) DocumentStore(org.apache.jackrabbit.oak.plugins.document.DocumentStore) MongoDocumentStore(org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentStore) RDBDocumentStore(org.apache.jackrabbit.oak.plugins.document.rdb.RDBDocumentStore) RDBDocumentStore(org.apache.jackrabbit.oak.plugins.document.rdb.RDBDocumentStore) OptionSet(joptsimple.OptionSet) MongoConnection(org.apache.jackrabbit.oak.plugins.document.util.MongoConnection)

Example 7 with OptionSpec

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);
}
Also used : OptionSpec(joptsimple.OptionSpec) Options(org.apache.jackrabbit.oak.run.cli.Options) IO(org.codehaus.groovy.tools.shell.IO) NodeStoreFixture(org.apache.jackrabbit.oak.run.cli.NodeStoreFixture) OptionSet(joptsimple.OptionSet) OptionParser(joptsimple.OptionParser)

Example 8 with OptionSpec

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;
}
Also used : OptionSpec(joptsimple.OptionSpec) Field(java.lang.reflect.Field) HashSet(java.util.HashSet)

Example 9 with OptionSpec

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.");
    }
}
Also used : OptionSpec(joptsimple.OptionSpec) OptionException(joptsimple.OptionException) OptionSet(joptsimple.OptionSet)

Example 10 with OptionSpec

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;
}
Also used : OptionSpec(joptsimple.OptionSpec) List(java.util.List) Properties(java.util.Properties)

Aggregations

OptionSpec (joptsimple.OptionSpec)24 OptionSet (joptsimple.OptionSet)15 ArgumentAcceptingOptionSpec (joptsimple.ArgumentAcceptingOptionSpec)14 OptionParser (joptsimple.OptionParser)14 ArrayList (java.util.ArrayList)10 Properties (java.util.Properties)8 ClusterMapConfig (com.github.ambry.config.ClusterMapConfig)7 VerifiableProperties (com.github.ambry.config.VerifiableProperties)7 ClusterAgentsFactory (com.github.ambry.clustermap.ClusterAgentsFactory)6 ClusterMap (com.github.ambry.clustermap.ClusterMap)6 File (java.io.File)5 MetricRegistry (com.codahale.metrics.MetricRegistry)4 BlobProperties (com.github.ambry.messageformat.BlobProperties)4 Throttler (com.github.ambry.utils.Throttler)4 FileWriter (java.io.FileWriter)4 HashSet (java.util.HashSet)4 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)4 AtomicLong (java.util.concurrent.atomic.AtomicLong)4 OptionException (joptsimple.OptionException)4 IOException (java.io.IOException)3