Search in sources :

Example 26 with OptionParser

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);
    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 27 with OptionParser

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;
}
Also used : OptionParser(joptsimple.OptionParser)

Example 28 with OptionParser

use of joptsimple.OptionParser in project jackrabbit-oak by apache.

the class OptionsTest method help.

@Test
public void help() throws Exception {
    OptionParser parser = new OptionParser();
    Options opts = new Options().withDisableSystemExit();
    opts.parseAndConfigure(parser, new String[] { "-h" });
    assertTrue(opts.getCommonOpts().isHelpRequested());
}
Also used : OptionParser(joptsimple.OptionParser) Test(org.junit.Test)

Example 29 with OptionParser

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());
}
Also used : OptionParser(joptsimple.OptionParser) Test(org.junit.Test)

Example 30 with OptionParser

use of joptsimple.OptionParser in project lavagna by digitalfondue.

the class Launcher method main.

public static void main(String[] args) throws Exception {
    OptionParser parser = new OptionParser();
    ArgumentAcceptingOptionSpec<Integer> portOption = parser.accepts("port", "Create an HTTP listener on port n (default 8080)").withRequiredArg().ofType(Integer.class);
    ArgumentAcceptingOptionSpec<String> bindAddressOption = parser.accepts("bindAddress", "Accept connections only on address addr (default: accept on any address)").withRequiredArg().ofType(String.class);
    ArgumentAcceptingOptionSpec<String> tmpDirOption = parser.accepts("tmpDir", "Temporary directory").withRequiredArg().ofType(String.class);
    ArgumentAcceptingOptionSpec<String> contextPathOption = parser.accepts("contextPath", "Set context path (default: /)").withRequiredArg().ofType(String.class);
    ArgumentAcceptingOptionSpec<String> cookiePrefixOption = parser.accepts("cookiePrefix", "Prefix the cookies").withRequiredArg().ofType(String.class);
    OptionSpecBuilder helpOption = parser.accepts("help", "Print this help message");
    parser.accepts("headless", "legacy parameter, ignored");
    parser.accepts("forwarded", "legacy parameter, ignored");
    parser.accepts("sslProxied", "legacy parameter, ignored");
    OptionSet options = parser.parse(args);
    if (options.has(helpOption)) {
        parser.printHelpOn(System.out);
        return;
    }
    int port = options.has(portOption) ? options.valueOf(portOption) : 8080;
    String bindAddress = options.has(bindAddressOption) ? options.valueOf(bindAddressOption) : "0.0.0.0";
    String contextPath = options.has(contextPathOption) ? options.valueOf(contextPathOption) : "/";
    if (options.has(cookiePrefixOption)) {
        String cookiePrefixValue = options.valueOf(cookiePrefixOption);
        System.out.println("Using cookie prefix " + cookiePrefixValue);
        System.setProperty(CookieNames.PROPERTY_NAME, cookiePrefixValue);
    }
    InetSocketAddress address = new InetSocketAddress(bindAddress, port);
    Server server = new Server(address);
    WebAppContext webapp = new WebAppContext();
    if (options.has(tmpDirOption)) {
        webapp.setTempDirectory(new File(options.valueOf(tmpDirOption)));
    }
    webapp.setContextPath(contextPath);
    webapp.setServer(server);
    webapp.setWar(war());
    webapp.setConfigurations(new Configuration[] { new WebInfConfiguration(), new WebXmlConfiguration(), new MetaInfConfiguration(), new AnnotationConfiguration(), new JettyWebXmlConfiguration() });
    server.setHandler(webapp);
    System.out.println("Starting jetty server " + Server.getVersion());
    System.out.println("Server is listening at " + address.toString());
    server.start();
    server.join();
}
Also used : Server(org.eclipse.jetty.server.Server) InetSocketAddress(java.net.InetSocketAddress) OptionParser(joptsimple.OptionParser) OptionSpecBuilder(joptsimple.OptionSpecBuilder) AnnotationConfiguration(org.eclipse.jetty.annotations.AnnotationConfiguration) OptionSet(joptsimple.OptionSet) File(java.io.File)

Aggregations

OptionParser (joptsimple.OptionParser)199 OptionSet (joptsimple.OptionSet)151 File (java.io.File)58 IOException (java.io.IOException)29 Test (org.junit.Test)28 OptionException (joptsimple.OptionException)25 ArrayList (java.util.ArrayList)21 Properties (java.util.Properties)16 List (java.util.List)15 OptionSpec (joptsimple.OptionSpec)14 Test (org.junit.jupiter.api.Test)12 VerifiableProperties (com.github.ambry.config.VerifiableProperties)11 FileNotFoundException (java.io.FileNotFoundException)9 BufferedReader (java.io.BufferedReader)8 ArgumentAcceptingOptionSpec (joptsimple.ArgumentAcceptingOptionSpec)8 FileReader (java.io.FileReader)7 OptionSpecBuilder (joptsimple.OptionSpecBuilder)7 Closer (com.google.common.io.Closer)6 Cluster (voldemort.cluster.Cluster)6 StoreDefinition (voldemort.store.StoreDefinition)6