List of usage examples for org.apache.commons.cli OptionBuilder withLongOpt
public static OptionBuilder withLongOpt(String newLongopt)
From source file:hr.fer.zemris.vhdllab.platform.support.CommandLineArgumentProcessor.java
@SuppressWarnings("static-access") private Options createOptions() { Options options = new Options(); options.addOption(OptionBuilder.withLongOpt(ENV_OPTION).hasArg().withValueSeparator().create()); return options; }
From source file:iDynoOptimizer.MOEAFramework26.src.org.moeaframework.analysis.sensitivity.ResultFileEvaluator.java
@SuppressWarnings("static-access") @Override/*from w w w . j av a 2s . com*/ public Options getOptions() { Options options = super.getOptions(); OptionGroup group = new OptionGroup(); group.setRequired(true); group.addOption(OptionBuilder.withLongOpt("problem").hasArg().withArgName("name").create('b')); group.addOption(OptionBuilder.withLongOpt("dimension").hasArg().withArgName("number").create('d')); options.addOptionGroup(group); options.addOption(OptionBuilder.withLongOpt("input").hasArg().withArgName("file").isRequired().create('i')); options.addOption( OptionBuilder.withLongOpt("output").hasArg().withArgName("file").isRequired().create('o')); options.addOption(OptionBuilder.withLongOpt("reference").hasArg().withArgName("file").create('r')); options.addOption(OptionBuilder.withLongOpt("force").create('f')); return options; }
From source file:net.freehal.ui.common.Main.java
@SuppressWarnings("static-access") public void run(String[] args) { Options options = new Options(); // general options options.addOption("h", "help", false, "display this help and exit"); options.addOption("v", "version", false, "output version information and exit"); // options related to the directory structure options.addOption(/*from www . j a v a 2 s . c om*/ OptionBuilder.withLongOpt("base").withDescription("the base directory for language data and caches") .hasArg().withArgName("DIRECTORY").create("b")); options.addOption( OptionBuilder.withLongOpt("language").withDescription("the natual language TEXT is written in") .hasArg().withArgName("LANG").create("l")); // interactive or non-interactive? options.addOption(OptionBuilder.withLongOpt("input").withDescription("a statement or question to answer") .hasArg().withArgName("TEXT").create("i")); // options for logging options.addOption(OptionBuilder.withLongOpt("log-file").withDescription("write logs to a file").hasArg() .withArgName("FILE").create()); options.addOption(OptionBuilder.withLongOpt("log-terminal") .withDescription("display logs in terminal " + "(default on Linux and Unix)").hasArg() .withArgName("FILE").create()); options.addOption("t", "think", false, "do some reasoning processes"); // optional extensions: interactive shell? if (Extensions.hasExtension("shell")) { Extension shell = (Extension) Extensions.getExtension("shell"); shell.addOptions(options); } // optional extensions: swing log window? if (Extensions.hasExtension("swing")) { Extension swing = (Extension) Extensions.getExtension("swing"); swing.addOptions(options); } // optional extensions: xmpp plugin if (Extensions.hasExtension("xmpp")) { Extension xmpp = (Extension) Extensions.getExtension("xmpp"); xmpp.addOptions(options); } if (args.length == 0) { printHelp(options); } else { // create the parser CommandLineParser parser = new GnuParser(); try { // parse command line arguments CommandLine line = parser.parse(options, args); parse(line, options); } catch (ParseException exp) { System.err.println(exp.getMessage()); SystemUtils.exit(1); } } SystemUtils.exit(0); }
From source file:iDynoOptimizer.MOEAFramework26.src.org.moeaframework.analysis.sensitivity.ResultFileMerger.java
@SuppressWarnings("static-access") @Override//from w w w . j a v a 2 s .c o m public Options getOptions() { Options options = super.getOptions(); OptionGroup group = new OptionGroup(); group.setRequired(true); group.addOption(OptionBuilder.withLongOpt("problem").hasArg().withArgName("name").create('b')); group.addOption(OptionBuilder.withLongOpt("dimension").hasArg().withArgName("number").create('d')); options.addOptionGroup(group); options.addOption(OptionBuilder.withLongOpt("epsilon").hasArg().withArgName("e1,e2,...").create('e')); options.addOption( OptionBuilder.withLongOpt("output").hasArg().withArgName("file").isRequired().create('o')); options.addOption(OptionBuilder.withLongOpt("resultFile").create('r')); return options; }
From source file:iDynoOptimizer.MOEAFramework26.src.org.moeaframework.analysis.sensitivity.SampleGenerator.java
@SuppressWarnings("static-access") @Override//from w ww .ja va 2s . c o m public Options getOptions() { Options options = super.getOptions(); options.addOption(OptionBuilder.withLongOpt("numberOfSamples").hasArg().withArgName("value").isRequired() .create('n')); options.addOption( OptionBuilder.withLongOpt("parameterFile").hasArg().withArgName("file").isRequired().create('p')); options.addOption( OptionBuilder.withLongOpt("method").hasArg().withArgName("name").isRequired().create('m')); options.addOption(OptionBuilder.withLongOpt("seed").hasArg().withArgName("value").create('s')); options.addOption(OptionBuilder.withLongOpt("output").hasArg().withArgName("file").create('o')); return options; }
From source file:edu.osu.ling.pep.Pep.java
/** * Invokes Pep from the command line./*from w w w . jav a 2 s.c o m*/ * <p> * The main work this method does, apart from tokenizing the arguments and * input tokens, is to load and parse the XML grammar file (as specified by * <code>-g</code> or <code>--grammar</code>). If any of the arguments * <code>-g</code>, <code>--grammar</code>, <code>-s</code>, * <code>--seed</code>, <code>-o</code>, <code>--option</code>, occur with * no argument following, this method prints an error notifying the user. * * @param args * The expected arguments are as follows, and can occur in any * particular order: * <ul> * <li><code>-g|--grammar <grammar file></code></li> <li> * <code>-s|--seed <seed category></code></li> <li><code> * -v|--verbose {verbosity level}</code></li> <li><code> * -o|--option <OPTION_NAME=value></code></li> <li><code> * -h|--help (prints usage information)</code></li> <li><code> * <token1 ... token<em>n</em>></code> (or <code>-</code> * for standard input)</li> * </ul> * <code>OPTION_NAME</code> must be the name of one of the * recognized {@link ParserOption options}. If <code>-h</code> or * <code>--help</code> occur anywhere in the arguments, usage * information is printed and no parsing takes place. */ @SuppressWarnings("static-access") public static final void main(final String[] args) { try { final Options opts = new Options(); opts.addOption(OptionBuilder.withLongOpt("grammar").withDescription("the grammar to use").hasArg() .isRequired().withArgName("grammar file").create('g')); opts.addOption(OptionBuilder.withLongOpt("seed").withDescription("the seed category to parse for") .hasArg().isRequired().withArgName("seed category").create('s')); opts.addOption(OptionBuilder.withLongOpt("verbose").withDescription("0-3").hasOptionalArg() .withArgName("verbosity level").create('v')); opts.addOption(OptionBuilder.withLongOpt("option").withDescription("sets parser options") .withArgName("OPTION=value").hasArgs(2).withValueSeparator() .withDescription("use value for given property").create("o")); opts.addOption(OptionBuilder.withLongOpt("help").withDescription("prints this message").create('h')); final CommandLineParser parser = new GnuParser(); try { final CommandLine line = parser.parse(opts, args); if (line.hasOption('h')) { Pep.printHelp(opts); } else { final int v = Integer.parseInt(line.getOptionValue('v', Integer.toString(Pep.V_PARSE))); if (v < 0) { throw new PepException("verbosity < 0: " + v); } Pep.verbosity = v; final Map<ParserOption, Boolean> options = new EnumMap<ParserOption, Boolean>( ParserOption.class); final Properties props = line.getOptionProperties("o"); for (final Object key : props.keySet()) { try { options.put(ParserOption.valueOf(key.toString()), Boolean.valueOf(props.get(key).toString())); } catch (final IllegalArgumentException iae) { Pep.printError("no option named " + key.toString()); Pep.printHelp(opts); return; } } final Pep pep = new Pep(options); // final Grammar grammar = // new GrammarParser(Pep.findGrammar(line // .getOptionValue('g'))).t.parse(); final List<?> ts = line.getArgList(); List<String> tokens = null; if (ts.isEmpty() || ts.get(0).equals("-")) { tokens = Pep.readTokens(new Scanner(System.in)); } else { tokens = new ArrayList<String>(ts.size()); for (final Object t : ts) { tokens.add(t.toString()); } } pep.lastParseStart = System.currentTimeMillis(); // try { // pep.parse(grammar, tokens, // new Category(line.getOptionValue('s'))); // } catch (final PepException ignore) { // // ignore here, we're listening // } } } catch (final ParseException pe) { Pep.printError("command-line syntax problem: " + pe.getMessage()); Pep.printHelp(opts); } } catch (final PepException pe) { final Throwable cause = pe.getCause(); Pep.printError((cause == null) ? pe : cause); } catch (final RuntimeException re) { Pep.printError(re); } }
From source file:iDynoOptimizer.MOEAFramework26.src.org.moeaframework.analysis.sensitivity.SetGenerator.java
@SuppressWarnings("static-access") @Override//from w w w .j av a 2 s. c om public Options getOptions() { Options options = super.getOptions(); options.addOption( OptionBuilder.withLongOpt("problem").hasArg().withArgName("name").isRequired().create('b')); options.addOption( OptionBuilder.withLongOpt("numberOfPoints").hasArg().withArgName("value").isRequired().create('n')); options.addOption(OptionBuilder.withLongOpt("seed").hasArg().withArgName("value").create('s')); options.addOption( OptionBuilder.withLongOpt("output").hasArg().withArgName("file").isRequired().create('o')); options.addOption(OptionBuilder.withLongOpt("epsilon").hasArg().withArgName("e1,e2,...").create('e')); return options; }
From source file:de.tudarmstadt.lt.lm.app.LineProbPerp.java
@SuppressWarnings("static-access") public LineProbPerp(String args[]) { Options opts = new Options(); opts.addOption(new Option("?", "help", false, "display this message")); opts.addOption(OptionBuilder.withLongOpt("port").withArgName("port-number").hasArg() .withDescription(/*www . ja v a2 s . c o m*/ String.format("Specifies the port on which the rmi registry listens (default: %d).", Registry.REGISTRY_PORT)) .create("rp")); opts.addOption(OptionBuilder.withLongOpt("host").withArgName("hostname").hasArg() .withDescription("Specifies the hostname on which the rmi registry listens (default: localhost).") .create("h")); opts.addOption(OptionBuilder.withLongOpt("file").withArgName("name").hasArg().withDescription( "Specify the file or directory that contains '.txt' files that are used as source for testing perplexity with the specified language model. Specify '-' to pipe from stdin. (default: '-').") .create("f")); opts.addOption(OptionBuilder.withLongOpt("out").withArgName("name").hasArg() .withDescription("Specify the output file. Specify '-' to use stdout. (default: '-').") .create("o")); opts.addOption(OptionBuilder.withLongOpt("name").withArgName("identifier").isRequired().hasArg() .withDescription("Specify the name of the language model provider that you want to connect to.") .create("i")); opts.addOption(OptionBuilder.withLongOpt("runparallel") .withDescription("Specify if processing should happen in parallel.").create("p")); try { CommandLine cmd = new ExtendedGnuParser(true).parse(opts, args); if (cmd.hasOption("help")) CliUtils.print_usage_quit(System.err, StartLM.class.getSimpleName(), opts, USAGE_HEADER, null, 0); _host = cmd.getOptionValue("host", "localhost"); _rmiport = Integer.parseInt(cmd.getOptionValue("port", String.valueOf(Registry.REGISTRY_PORT))); _file = cmd.getOptionValue("file", "-"); _out = cmd.getOptionValue("out", "-"); _name = cmd.getOptionValue("name"); _parallel = cmd.hasOption("runparallel"); } catch (Exception e) { LOG.error("{}: {}- {}", _rmi_string, e.getClass().getSimpleName(), e.getMessage()); CliUtils.print_usage_quit(System.err, getClass().getSimpleName(), opts, USAGE_HEADER, String.format("%s: %s%n", e.getClass().getSimpleName(), e.getMessage()), 1); } _rmi_string = String.format("rmi://%s:%d/%s", _host, _rmiport, _name); }
From source file:com.linkedin.databus.bootstrap.common.BootstrapConfigBase.java
@SuppressWarnings("static-access") public static Properties loadConfigProperties(String[] args) throws IOException { CommandLineParser cliParser = new GnuParser(); Option dbOption = OptionBuilder.withLongOpt(BOOTSTRAP_DB_PROPS_OPT_LONG_NAME) .withDescription("Bootstrap producer properties to use").hasArg().withArgName("property_file") .create(BOOTSTRAP_DB_PROP_OPT_CHAR); Options options = new Options(); options.addOption(dbOption);/*from w w w . ja v a 2 s .c om*/ CommandLine cmd = null; try { cmd = cliParser.parse(options, args); } catch (ParseException pe) { throw new RuntimeException("BootstrapConfig: failed to parse command-line options.", pe); } Properties props = null; if (cmd.hasOption(BOOTSTRAP_DB_PROP_OPT_CHAR)) { String propFile = cmd.getOptionValue(BOOTSTRAP_DB_PROP_OPT_CHAR); LOG.info("Loading bootstrap DB config from properties file " + propFile); props = new Properties(); FileInputStream f = new FileInputStream(propFile); try { props.load(f); } finally { if (null != f) f.close(); } } else { LOG.info("Using system properties for bootstrap DB config"); } return props; }
From source file:de.tudarmstadt.lt.lm.app.PerplexityClient.java
/** * /* w ww . j av a 2 s. co m*/ */ @SuppressWarnings("static-access") public PerplexityClient(String args[]) { Options opts = new Options(); opts.addOption(new Option("?", "help", false, "display this message")); opts.addOption(OptionBuilder.withLongOpt("port").withArgName("port-number").hasArg() .withDescription( String.format("Specifies the port on which the rmi registry listens (default: %d).", Registry.REGISTRY_PORT)) .create("p")); opts.addOption(OptionBuilder.withLongOpt("selftest") .withDescription("Run a selftest, compute perplexity of ngrams in specified LM.").create("s")); opts.addOption(OptionBuilder.withLongOpt("quiet").withDescription("Run with minimum outout on stdout.") .create("q")); opts.addOption(OptionBuilder.withLongOpt("skipoov").hasOptionalArg().withArgName("{true|false}") .withDescription("Do not consider oov terms, i.e. ngrams that end in an oov term. (default: false)") .create()); opts.addOption(OptionBuilder.withLongOpt("skipoovreflm").hasOptionalArg().withArgName("{true|false}") .withDescription( "Do not consider oov terms regarding the oovreflm, i.e. ngrams that end in an oov term. (default: false)") .create()); opts.addOption(OptionBuilder.withLongOpt("oovreflm").withArgName("identifier").hasArg().withDescription( "Do not consider oov terms with respect to the provided lm, i.e. ngrams that end in an oov term in the referenced lm. (default use current lm)") .create()); opts.addOption(OptionBuilder.withLongOpt("host").withArgName("hostname").hasArg() .withDescription("Specifies the hostname on which the rmi registry listens (default: localhost).") .create("h")); opts.addOption(OptionBuilder.withLongOpt("file").withArgName("name").hasArg().withDescription( "Specify the file or directory that contains '.txt' files that are used as source for testing perplexity with the specified language model. Specify '-' to pipe from stdin. (default: '-').") .create("f")); opts.addOption(OptionBuilder.withLongOpt("out").withArgName("name").hasArg() .withDescription("Specify the output file. Specify '-' to use stdout. (default: '-').") .create("o")); opts.addOption(OptionBuilder.withLongOpt("id").withArgName("identifier").isRequired().hasArg() .withDescription("Specify the name of the language model provider that you want to connect to.") .create("i")); opts.addOption(OptionBuilder.withLongOpt("one_ngram_per_line").hasOptionalArg().withArgName("{true|false}") .withDescription( "Specify if the input file contains one ngram per line or sentences. (default: false)") .create()); try { CommandLine cmd = new ExtendedGnuParser(true).parse(opts, args); if (cmd.hasOption("help")) CliUtils.print_usage_quit(System.err, StartLM.class.getSimpleName(), opts, USAGE_HEADER, null, 0); _host = cmd.getOptionValue("host", "localhost"); _rmiport = Integer.parseInt(cmd.getOptionValue("port", String.valueOf(Registry.REGISTRY_PORT))); _file = cmd.getOptionValue("file", "-"); _out = cmd.getOptionValue("out", "-"); _id = cmd.getOptionValue("id"); _host = cmd.getOptionValue("host", "localhost"); _selftest = cmd.hasOption("selftest"); _quiet = cmd.hasOption("quiet"); _no_oov = cmd.hasOption("skipoov"); if (_no_oov && cmd.getOptionValue("skipoov") != null) _no_oov = Boolean.parseBoolean(cmd.getOptionValue("skipoov")); _no_oov_reflm = cmd.hasOption("skipoovreflm"); if (_no_oov_reflm && cmd.getOptionValue("skipoovreflm") != null) _no_oov_reflm = Boolean.parseBoolean(cmd.getOptionValue("skipoovreflm")); _one_ngram_per_line = cmd.hasOption("one_ngram_per_line"); if (_one_ngram_per_line && cmd.getOptionValue("one_ngram_per_line") != null) _one_ngram_per_line = Boolean.parseBoolean(cmd.getOptionValue("one_ngram_per_line")); _oovreflm_name = cmd.getOptionValue("oovreflm"); } catch (Exception e) { LOG.error("{}: {}- {}", _rmi_string, e.getClass().getSimpleName(), e.getMessage()); CliUtils.print_usage_quit(System.err, StartLM.class.getSimpleName(), opts, USAGE_HEADER, String.format("%s: %s%n", e.getClass().getSimpleName(), e.getMessage()), 1); } _rmi_string = String.format("rmi://%s:%d/%s", _host, _rmiport, _id); }