List of usage examples for org.apache.commons.cli OptionGroup addOption
public OptionGroup addOption(Option option)
Option
to this group. From source file:org.esxx.Main.java
public static void main(String[] args) { // (Try to) Load embedded H2 database JDBC driver into memory try {// w w w. j a va2s . c o m Class.forName("org.h2.Driver"); } catch (ClassNotFoundException ignored) { } Options opt = new Options(); OptionGroup mode_opt = new OptionGroup(); // (Remember: -u/--user, -p/--pidfile and -j/jvmargs are used by the wrapper script) mode_opt.addOption(new Option("b", "bind", true, ("Listen for FastCGI requests on " + "this <port>"))); mode_opt.addOption(new Option("A", "ajp", true, ("Listen for AJP13 requests on " + "this <port>"))); mode_opt.addOption(new Option("H", "http", true, ("Listen for HTTP requests on " + "this <port>"))); mode_opt.addOption(new Option("s", "script", false, "Force script mode.")); mode_opt.addOption(new Option("S", "shell", false, "Enter ESXX shell mode.")); mode_opt.addOption(new Option(null, "db-console", false, "Open H2's database console.")); mode_opt.addOption(new Option(null, "version", false, "Display version and exit")); opt.addOptionGroup(mode_opt); opt.addOption("n", "no-handler", true, "FCGI requests are direct, without extra handler"); opt.addOption("r", "http-root", true, "Set AJP/FCGI/HTTP root directory (or file)"); // opt.addOption("d", "enable-debugger", false, "Enable esxx.debug()"); // opt.addOption("D", "start-debugger", false, "Start debugger"); opt.addOption("?", "help", false, "Show help"); try { CommandLineParser parser = new GnuParser(); CommandLine cmd = parser.parse(opt, args, false); int fastcgi_port = -1; int ajp_port = -1; int http_port = -1; boolean run_shell = false; String[] script = null; if (cmd.hasOption('?')) { usage(opt, null, 0); } if (cmd.hasOption('b')) { fastcgi_port = Integer.parseInt(cmd.getOptionValue('b')); } else if (cmd.hasOption('A')) { ajp_port = Integer.parseInt(cmd.getOptionValue('A')); } else if (cmd.hasOption('H')) { http_port = Integer.parseInt(cmd.getOptionValue('H')); } else if (cmd.hasOption('s')) { script = cmd.getArgs(); } else if (cmd.hasOption('S')) { run_shell = true; } else if (cmd.hasOption("db-console")) { org.h2.tools.Console.main(cmd.getArgs()); return; } else if (cmd.hasOption("version")) { Properties p = new Properties(); p.loadFromXML(Main.class.getResourceAsStream("/rsrc/esxx.properties")); System.err.println(p.getProperty("version")); return; } else { // Guess execution mode by looking at FCGI_PORT String fcgi_port = System.getenv("FCGI_PORT"); if (fcgi_port != null) { fastcgi_port = Integer.parseInt(fcgi_port); } else { // Default mode is to execute a JS script script = cmd.getArgs(); } } if (script != null) { Properties p = System.getProperties(); String forever = Long.toString(3600 * 24 * 365 * 10 /* 10 years */); // "Never" unload Applications in script mode p.setProperty("esxx.cache.apps.max_age", forever); // Kill process immediately on Ctrl-C p.setProperty("esxx.app.clean_shutdown", "false"); } ESXX esxx = ESXX.initInstance(System.getProperties(), null); if (script != null || run_shell) { // Lower default log level a bit esxx.getLogger().setLevel(java.util.logging.Level.INFO); } esxx.setNoHandlerMode(cmd.getOptionValue('n', "lighttpd.*")); // Install our ResponseCache implementation // java.net.ResponseCache.setDefault(new org.esxx.cache.DBResponseCache("/tmp/ESXX.WebCache", // Integer.MAX_VALUE, // Long.MAX_VALUE, // Long.MAX_VALUE)); // Default is to serve the current directory URI fs_root_uri = ESXX.createFSRootURI(cmd.getOptionValue('r', "")); if (fastcgi_port != -1 && !cmd.hasOption('r')) { // If not provided in FastCGI mode, use ${PATH_TRANSLATED} fs_root_uri = null; } if (fastcgi_port != -1) { FCGIRequest.runServer(fastcgi_port, fs_root_uri); } else if (ajp_port != -1) { Jetty.runJettyServer(-1, ajp_port, fs_root_uri); } else if (http_port != -1) { Jetty.runJettyServer(http_port, -1, fs_root_uri); } else if (run_shell) { ShellRequest sr = new ShellRequest(); sr.initRequest(); ESXX.Workload wl = esxx.addRequest(sr, sr, -1 /* no timeout for the shell */); try { System.exit((Integer) wl.getResult()); } catch (java.util.concurrent.CancellationException ex) { ex.printStackTrace(); System.exit(5); } } else if (script != null && script.length != 0) { File file = new File(script[0]); ScriptRequest sr = new ScriptRequest(); sr.initRequest(file.toURI(), script); ESXX.Workload wl = esxx.addRequest(sr, sr, -1 /* no timeout for scripts */); try { System.exit((Integer) wl.getResult()); } catch (java.util.concurrent.CancellationException ex) { ex.printStackTrace(); System.exit(5); } } else { usage(opt, "Required argument missing", 10); } } catch (ParseException ex) { usage(opt, ex.getMessage(), 10); } catch (IOException ex) { System.err.println("I/O error: " + ex.getMessage()); System.exit(20); } catch (Exception ex) { ex.printStackTrace(); System.exit(20); } System.exit(0); }
From source file:org.glite.security.voms.admin.util.ShutdownClient.java
/** * Initializes the CLI parsing options/*from w ww .ja v a2 s. co m*/ */ private static void initOptions() { OptionGroup og = new OptionGroup(); og.addOption(new Option(ARG_VO, true, ARG_VO_DESC)); og.addOption(new Option(ARG_PORT, true, ARG_PORT_DESC)); cliOptions.addOptionGroup(og); cliOptions.addOption(new Option(ARG_PASSWORD, true, ARG_PASSWORD_DESC)); }
From source file:org.goobi.eadmgr.Cli.java
@Override @SuppressWarnings("AccessStaticViaInstance") // workaround for screwed OptionBuilder API public void initOptions() { options = new Options(); // mutually exclusive main commands OptionGroup mainCommands = new OptionGroup(); mainCommands.addOption(new Option("h", "help", false, "Print this usage information")); mainCommands.addOption(//from w ww . j a v a2 s. c o m new Option("l", "list-folder-ids", false, "List all folder IDs available for process creation.")); mainCommands.addOption(new Option("c", "create-process", true, "Extracted data for given folder ID as process creation message to configured ActiveMQ server.")); options.addOptionGroup(mainCommands); // additional switches options.addOption(OptionBuilder.withLongOpt("validate").withDescription( "Validate XML structure of the EAD document. Exits with error code 1 if validation fails. Can be used without other commands for just validating files.") .create()); options.addOption(OptionBuilder.withLongOpt("dry-run") .withDescription("Print folder information instead of sending it.").create()); options.addOption("v", "verbose", false, "Be verbose about what is going on."); options.addOption("u", "url", true, MessageFormat.format("ActiveMQ Broker URL. If not given the broker is contacted at \"{0}\".\n" + "Note that using the failover protocol will block the program forever if the ActiveMQ host is not reachable unless you specify the \"timeout\" parameter in the URL. See {1} for more information.", DEFAULT_BROKER_URL, ACTIVEMQ_CONFIGURING_URL)); options.addOption("q", "queue", true, MessageFormat.format( "ActiveMQ Subject Queue. If not given messages get enqueue at \"{0}\".", DEFAULT_SUBJECT_QUEUE)); options.addOption(OptionBuilder.withLongOpt("topic-queue") .withDescription(MessageFormat.format( "ActiveMQ result topic Queue. If not given wait for result message posting at \"{0}\".", DEFAULT_RESULT_TOPIC)) .hasArg().create()); options.addOption("t", "template", true, MessageFormat .format("Goobi Process Template name. If not given \"{0}\" is used.", DEFAULT_PROCESS_TEMPLATE)); options.addOption("d", "doctype", true, MessageFormat.format("Goobi Doctype name. If not given \"{0}\" is used.", DEFAULT_DOCTYPE)); options.addOption(OptionBuilder.withLongOpt("use-folder-id").withDescription( "Use folder ID when generating ActiveMQ Message IDs. If not given a random 128 bit universally unique identifier (UUID) is generated.") .create()); options.addOption(OptionBuilder.withLongOpt("collection") .withDescription("Name of a collection to which the newly created process should be assigned.") .hasArg().create("C")); options.addOption(OptionBuilder .withDescription( "User defined option in the form of <key>=<value> to append to the ActiveMQ message.") .hasArgs().create("O")); options.addOption("x", "extraction-profile", true, MessageFormat.format( "XSLT EAD extraction profile name. Either an absolute pathname or a file that can be found on the classpath. If not given \"{0}\" is used.", DEFAULT_EXTRACTION_PROFILE)); }
From source file:org.hashes.ui.CliOption.java
/** * Build all command line options.//from w w w. j a va 2s .co m * * @return command line options */ public static Options buildOptions() { final OptionGroup lang = new OptionGroup(); lang.setRequired(false); lang.addOption(PHP.getOption()); lang.addOption(JAVA.getOption()); lang.addOption(ASP.getOption()); lang.addOption(V8.getOption()); final Options options = new Options(); options.addOption(HELP.getOption()); options.addOption(PROGRESS_BAR.getOption()); options.addOption(SAVE_KEYS.getOption()); options.addOption(WAIT.getOption()); options.addOption(NEW.getOption()); options.addOption(KEYS.getOption()); options.addOption(REQUESTS.getOption()); options.addOption(CLIENTS.getOption()); options.addOption(CONNECTION_TIMEOUT.getOption()); options.addOption(READ_TIMEOUT.getOption()); options.addOption(MITM_WORKER_THREADS.getOption()); options.addOption(HEADER.getOption()); options.addOptionGroup(lang); return options; }
From source file:org.itstechupnorth.walrus.ActOption.java
@Override public void addTo(Options options) { final OptionGroup group = new OptionGroup(); for (Opt opt : Opt.values()) { group.addOption(opt.option()); }//from w w w .j a va 2s.c om options.addOptionGroup(group); }
From source file:org.jalphanode.ui.JalphaNodeCli.java
private Options buildCmdOptions() { final OptionGroup optionGroup = new OptionGroup(); optionGroup.setRequired(true);/*w w w. ja v a2 s . c o m*/ optionGroup.addOption(ComandLineOptions.CONFIG_PATH.getOption()); optionGroup.addOption(ComandLineOptions.GUI.getOption()); optionGroup.addOption(ComandLineOptions.HELP.getOption()); final Options options = new Options(); options.addOptionGroup(optionGroup); return options; }
From source file:org.javaan.commands.BaseDependencyGraphCommand.java
@Override public Options buildCommandLineOptions(Options options) { options.addOption(StandardOptions.FILTER); OptionGroup outputVariations = new OptionGroup(); outputVariations.addOption(StandardOptions.LEAVES); outputVariations.addOption(StandardOptions.DISPLAY_2D_GRAPH); options.addOptionGroup(outputVariations); options.addOption(StandardOptions.RESOLVE_DEPENDENCIES_IN_CLASS_HIERARCHY); options.addOption(StandardOptions.RESOLVE_METHOD_IMPLEMENTATIONS); return options; }
From source file:org.javaan.commands.ListClasses.java
@Override public Options buildCommandLineOptions(Options options) { OptionGroup additionalInformation = new OptionGroup(); additionalInformation.addOption(StandardOptions.SUPER_TYPES).addOption(StandardOptions.SPECIALIZATIONS) .addOption(StandardOptions.INTERFACES).addOption(StandardOptions.METHODS) .addOption(StandardOptions.VIRTUAL_METHODS); options.addOptionGroup(additionalInformation); options.addOption(StandardOptions.FILTER); return options; }
From source file:org.javaan.commands.ListInterfaces.java
@Override public Options buildCommandLineOptions(Options options) { OptionGroup additionalInformation = new OptionGroup(); additionalInformation.addOption(StandardOptions.SUPER_TYPES).addOption(StandardOptions.SPECIALIZATIONS) .addOption(StandardOptions.IMPLEMENTATIONS).addOption(StandardOptions.METHODS) .addOption(StandardOptions.VIRTUAL_METHODS); options.addOptionGroup(additionalInformation); options.addOption(StandardOptions.FILTER); return options; }
From source file:org.jboss.as.security.vault.VaultTool.java
/** * Build options for non-interactive VaultTool usage scenario. * * @return//from w w w .ja va2s . c om */ private void initOptions() { options = new Options(); options.addOption("k", KEYSTORE_PARAM, true, SecurityLogger.ROOT_LOGGER.cmdLineKeyStoreURL()); options.addOption("p", KEYSTORE_PASSWORD_PARAM, true, SecurityLogger.ROOT_LOGGER.cmdLineKeyStorePassword()); options.addOption("e", ENC_DIR_PARAM, true, SecurityLogger.ROOT_LOGGER.cmdLineEncryptionDirectory()); options.addOption("s", SALT_PARAM, true, SecurityLogger.ROOT_LOGGER.cmdLineSalt()); options.addOption("i", ITERATION_PARAM, true, SecurityLogger.ROOT_LOGGER.cmdLineIterationCount()); options.addOption("v", ALIAS_PARAM, true, SecurityLogger.ROOT_LOGGER.cmdLineVaultKeyStoreAlias()); options.addOption("b", VAULT_BLOCK_PARAM, true, SecurityLogger.ROOT_LOGGER.cmdLineVaultBlock()); options.addOption("a", ATTRIBUTE_PARAM, true, SecurityLogger.ROOT_LOGGER.cmdLineAttributeName()); options.addOption("t", CREATE_KEYSTORE_PARAM, false, SecurityLogger.ROOT_LOGGER.cmdLineAutomaticallyCreateKeystore()); OptionGroup og = new OptionGroup(); Option x = new Option("x", SEC_ATTR_VALUE_PARAM, true, SecurityLogger.ROOT_LOGGER.cmdLineSecuredAttribute()); Option c = new Option("c", CHECK_SEC_ATTR_EXISTS_PARAM, false, SecurityLogger.ROOT_LOGGER.cmdLineCheckAttribute()); Option r = new Option("r", REMOVE_SEC_ATTR_PARAM, false, SecurityLogger.ROOT_LOGGER.cmdLineRemoveSecuredAttribute()); Option h = new Option("h", HELP_PARAM, false, SecurityLogger.ROOT_LOGGER.cmdLineHelp()); og.addOption(x); og.addOption(c); og.addOption(r); og.addOption(h); og.setRequired(true); options.addOptionGroup(og); }