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);
}
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;
}
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());
}
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 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();
}
Aggregations