List of usage examples for org.apache.commons.cli Option Option
public Option(String opt, String longOpt, boolean hasArg, String description) throws IllegalArgumentException
From source file:esiptestbed.mudrod.main.MudrodEngine.java
/** * Main program invocation. Accepts one argument denoting location (on disk) * to a log file which is to be ingested. Help will be provided if invoked * with incorrect parameters./*from w ww. j a v a 2s.c o m*/ * * @param args * {@link java.lang.String} array contaning correct parameters. */ public static void main(String[] args) { // boolean options Option helpOpt = new Option("h", "help", false, "show this help message"); // preprocessing + processing Option fullIngestOpt = new Option("f", FULL_INGEST, false, "begin full ingest Mudrod workflow"); // processing only, assuming that preprocessing results is in logDir Option processingOpt = new Option("p", PROCESSING, false, "begin processing with preprocessing results"); // import raw web log into Elasticsearch Option logIngestOpt = new Option("l", LOG_INGEST, false, "begin log ingest without any processing only"); // preprocessing web log, assuming web log has already been imported Option sessionReconOpt = new Option("s", SESSION_RECON, false, "begin session reconstruction"); // calculate vocab similarity from session reconstrution results Option vocabSimFromOpt = new Option("v", VOCAB_SIM_FROM_LOG, false, "begin similarity calulation from web log Mudrod workflow"); // add metadata and ontology preprocessing and processing results into web // log vocab similarity Option addMetaOntoOpt = new Option("a", ADD_META_ONTO, false, "begin adding metadata and ontology results"); // argument options Option logDirOpt = Option.builder(LOG_DIR).required(true).numberOfArgs(1).hasArg(true) .desc("the log directory to be processed by Mudrod").argName(LOG_DIR).build(); // create the options Options options = new Options(); options.addOption(helpOpt); options.addOption(logIngestOpt); options.addOption(fullIngestOpt); options.addOption(processingOpt); options.addOption(sessionReconOpt); options.addOption(vocabSimFromOpt); options.addOption(addMetaOntoOpt); options.addOption(logDirOpt); CommandLineParser parser = new DefaultParser(); try { CommandLine line = parser.parse(options, args); String processingType = null; if (line.hasOption(LOG_INGEST)) { processingType = LOG_INGEST; } else if (line.hasOption(FULL_INGEST)) { processingType = FULL_INGEST; } else if (line.hasOption(PROCESSING)) { processingType = PROCESSING; } else if (line.hasOption(SESSION_RECON)) { processingType = SESSION_RECON; } else if (line.hasOption(VOCAB_SIM_FROM_LOG)) { processingType = VOCAB_SIM_FROM_LOG; } else if (line.hasOption(ADD_META_ONTO)) { processingType = ADD_META_ONTO; } String dataDir = line.getOptionValue(LOG_DIR).replace("\\", "/"); if (!dataDir.endsWith("/")) { dataDir += "/"; } MudrodEngine me = new MudrodEngine(); me.loadConfig(); me.props.put(LOG_DIR, dataDir); me.es = new ESDriver(me.getConfig()); me.spark = new SparkDriver(); loadFullConfig(me, dataDir); if (processingType != null) { switch (processingType) { case LOG_INGEST: me.logIngest(); break; case PROCESSING: me.startProcessing(); break; case SESSION_RECON: me.sessionRestruction(); break; case VOCAB_SIM_FROM_LOG: me.vocabSimFromLog(); break; case ADD_META_ONTO: me.addMetaAndOntologySim(); break; case FULL_INGEST: me.startFullIngest(); break; default: break; } } me.end(); } catch (Exception e) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp( "MudrodEngine: 'logDir' argument is mandatory. " + "User must also provide an ingest method.", options, true); LOG.error("Error inputting command line!", e); return; } }
From source file:client.MultiplexingClient.java
public static void main(String[] args) throws Exception { // Prepare to parse the command line Options options = new Options(); Option sslOpt = new Option("s", "ssl", false, "Use SSL"); Option debugOpt = new Option("d", true, "Debug level (NONE, FINER, FINE, CONFIG, INFO, WARNING, SEVERE. Default INFO."); Option numConnectionsOpt = new Option("n", true, "Number of connections to establish. [Default: 1]"); Option numPcktOpt = new Option("p", true, "Number of packets to send in each connection. [Default: 20]"); Option pcktMaxSizeOpt = new Option("m", true, "Maximum size of packets. [Default: 4096]"); Option help = new Option("h", "print this message"); options.addOption(help);//from ww w . j av a 2s. co m options.addOption(debugOpt); options.addOption(numConnectionsOpt); options.addOption(numPcktOpt); options.addOption(pcktMaxSizeOpt); options.addOption(sslOpt); CommandLineParser parser = new PosixParser(); // parse the command line arguments CommandLine line = parser.parse(options, args); if (line.hasOption(help.getOpt()) || line.getArgs().length < 1) { showUsage(options); return; } if (line.hasOption(sslOpt.getOpt())) { channelFactory = new SSLChannelFactory(true, TRUSTSTORE, TRUSTSTORE_PASSWORD); } else { channelFactory = new PlainChannelFactory(); } if (line.hasOption(numConnectionsOpt.getOpt())) { connectionCount = Integer.parseInt(line.getOptionValue(numConnectionsOpt.getOpt())); } else { connectionCount = 1; } if (line.hasOption(numPcktOpt.getOpt())) { packetsToSend = Integer.parseInt(line.getOptionValue(numPcktOpt.getOpt())); } else { packetsToSend = 20; } if (line.hasOption(pcktMaxSizeOpt.getOpt())) { maxPcktSize = Integer.parseInt(line.getOptionValue(pcktMaxSizeOpt.getOpt())); } else { maxPcktSize = 4096; } InetSocketAddress remotePoint; try { String host = line.getArgs()[0]; int colonIndex = host.indexOf(':'); remotePoint = new InetSocketAddress(host.substring(0, colonIndex), Integer.parseInt(host.substring(colonIndex + 1))); } catch (Exception e) { showUsage(options); return; } // Setups the logging context for Log4j // NDC.push(Thread.currentThread().getName()); st = new SelectorThread(); for (int i = 0; i < connectionCount; i++) { new MultiplexingClient(remotePoint); // Must sleep for a while between opening connections in order // to give the remote host enough time to handle them. Otherwise, // the remote host backlog will get full and the connection // attemps will start to be refused. Thread.sleep(100); } }
From source file:edu.cornell.med.icb.R.RUtils.java
public static void main(final String[] args) throws ParseException, ConfigurationException { final Options options = new Options(); final Option helpOption = new Option("h", "help", false, "Print this message"); options.addOption(helpOption);//from w ww .j av a 2s.co m final Option startupOption = new Option(Mode.startup.name(), Mode.startup.name(), false, "Start Rserve process"); final Option shutdownOption = new Option(Mode.shutdown.name(), Mode.shutdown.name(), false, "Shutdown Rserve process"); final Option validateOption = new Option(Mode.validate.name(), Mode.validate.name(), false, "Validate that Rserve processes are running"); final OptionGroup optionGroup = new OptionGroup(); optionGroup.addOption(startupOption); optionGroup.addOption(shutdownOption); optionGroup.addOption(validateOption); optionGroup.setRequired(true); options.addOptionGroup(optionGroup); final Option portOption = new Option("port", "port", true, "Use specified port to communicate with the Rserve process"); portOption.setArgName("port"); portOption.setType(int.class); options.addOption(portOption); final Option hostOption = new Option("host", "host", true, "Communicate with the Rserve process on the given host"); hostOption.setArgName("hostname"); hostOption.setType(String.class); options.addOption(hostOption); final Option userOption = new Option("u", "username", true, "Username to send to the Rserve process"); userOption.setArgName("username"); userOption.setType(String.class); options.addOption(userOption); final Option passwordOption = new Option("p", "password", true, "Password to send to the Rserve process"); passwordOption.setArgName("password"); passwordOption.setType(String.class); options.addOption(passwordOption); final Option configurationOption = new Option("c", "configuration", true, "Configuration file or url to read from"); configurationOption.setArgName("configuration"); configurationOption.setType(String.class); options.addOption(configurationOption); final Parser parser = new BasicParser(); final CommandLine commandLine; try { commandLine = parser.parse(options, args); } catch (ParseException e) { usage(options); throw e; } int exitStatus = 0; if (commandLine.hasOption("h")) { usage(options); } else { Mode mode = null; for (final Mode potentialMode : Mode.values()) { if (commandLine.hasOption(potentialMode.name())) { mode = potentialMode; break; } } final ExecutorService threadPool = Executors.newCachedThreadPool(); if (commandLine.hasOption("configuration")) { final String configurationFile = commandLine.getOptionValue("configuration"); LOG.info("Reading configuration from " + configurationFile); XMLConfiguration configuration; try { final URL configurationURL = new URL(configurationFile); configuration = new XMLConfiguration(configurationURL); } catch (MalformedURLException e) { // resource is not a URL: attempt to get the resource from a file LOG.debug("Configuration is not a valid url"); configuration = new XMLConfiguration(configurationFile); } configuration.setValidating(true); final int numberOfRServers = configuration.getMaxIndex("RConfiguration.RServer") + 1; boolean failed = false; for (int i = 0; i < numberOfRServers; i++) { final String server = "RConfiguration.RServer(" + i + ")"; final String host = configuration.getString(server + "[@host]"); final int port = configuration.getInt(server + "[@port]", RConfigurationUtils.DEFAULT_RSERVE_PORT); final String username = configuration.getString(server + "[@username]"); final String password = configuration.getString(server + "[@password]"); final String command = configuration.getString(server + "[@command]", DEFAULT_RSERVE_COMMAND); if (executeMode(mode, threadPool, host, port, username, password, command) != 0) { failed = true; // we have other hosts to check so keep a failed state } } if (failed) { exitStatus = 3; } } else { final String host = commandLine.getOptionValue("host", "localhost"); final int port = Integer.valueOf(commandLine.getOptionValue("port", "6311")); final String username = commandLine.getOptionValue("username"); final String password = commandLine.getOptionValue("password"); exitStatus = executeMode(mode, threadPool, host, port, username, password, null); } threadPool.shutdown(); } System.exit(exitStatus); }
From source file:com.opengamma.component.tool.DbCreateTool.java
private static Option createDropExistingOption() { return new Option(DROP_EXISTING_OPTION, "drop", false, "whether to drop any existing contents"); }
From source file:com.ibm.watson.app.common.tools.utils.CliUtils.java
public static Option createOption(String opt, String longOpt, boolean hasArg, String description) { return new Option(opt, longOpt, hasArg, description); }
From source file:com.alibaba.rocketmq.srvutil.ServerUtil.java
public static Options buildCommandlineOptions(final Options options) { Option opt = new Option("h", "help", false, "Print help"); opt.setRequired(false);// w w w .j av a 2s . c o m options.addOption(opt); opt = new Option("n", "namesrvAddr", true, "Name server address list, eg: 192.168.0.1:9876;192.168.0.2:9876"); opt.setRequired(false); options.addOption(opt); return options; }
From source file:com.avira.couchdoop.ArgsHelper.java
public static Option getOptionFromArg(Args.ArgDef arg) { Option option = new Option(arg.getShortName() + "", arg.getLongName(), arg.hasArg, arg.description); option.setRequired(arg.isRequired);//from ww w.j a v a 2 s . c om return option; }
From source file:com.opengamma.integration.marketdata.WatchListRecorder.java
/** * Main entry point./*from w w w . j a va 2 s. com*/ * * @param args the arguments * @throws Exception if an error occurs */ public static void main(final String[] args) throws Exception { // CSIGNORE final CommandLineParser parser = new PosixParser(); final Options options = new Options(); final Option outputFileOpt = new Option("o", "output", true, "output file"); outputFileOpt.setRequired(true); options.addOption(outputFileOpt); final Option urlOpt = new Option("u", "url", true, "server url"); options.addOption(urlOpt); String outputFile = "watchList.txt"; String url = "http://localhost:8080/jax"; try { final CommandLine cmd = parser.parse(options, args); outputFile = cmd.getOptionValue("output"); url = cmd.getOptionValue("url"); } catch (final ParseException exp) { s_logger.error("Option parsing failed: {}", exp.getMessage()); System.exit(0); } final WatchListRecorder recorder = create(URI.create(url), "main", "combined"); recorder.addWatchScheme(ExternalSchemes.BLOOMBERG_TICKER); recorder.addWatchScheme(ExternalSchemes.BLOOMBERG_BUID); final PrintWriter pw = new PrintWriter(outputFile); recorder.setPrintWriter(pw); recorder.run(); pw.close(); System.exit(0); }
From source file:com.ibm.watson.app.common.tools.utils.CliUtils.java
public static Option createOption(String opt, String longOpt, boolean hasArg, String description, boolean required, String argName) { Option option = new Option(opt, longOpt, hasArg, description); option.setRequired(required);//from w ww . j ava 2s.co m option.setArgName(argName); return option; }
From source file:com.ztesoft.zsmart.remoting.util.ServerUtil.java
public static Options buildCommandlineOptions(final Options options) { Option opt = new Option("h", "help", false, "Print help"); opt.setRequired(false);// w ww . ja va 2s .c om options.addOption(opt); opt = new Option("n", "namesrvAddr", true, "Name server address list,eg:192.168.1.1:9876"); opt.setRequired(true); options.addOption(opt); return options; }