List of usage examples for org.apache.commons.cli OptionBuilder withLongOpt
public static OptionBuilder withLongOpt(String newLongopt)
From source file:com.linkedin.databus2.core.schema.tools.AvroConvertMain.java
@SuppressWarnings("static-access") public AvroConvertCli() { Option helpOption = OptionBuilder.withLongOpt(HELP_OPT_NAME).withDescription("this help screen") .create(HELP_OPT_CHAR);//from w w w . jav a 2 s. com Option inpFormatOption = OptionBuilder.withLongOpt(INPUT_FORMAT_OPT_NAME) .withDescription("Input format: JSON, JSON_LINES, BINARY").hasArg().withArgName("format") .create(INPUT_FORMAT_OPT_CHAR); Option outFormatOption = OptionBuilder.withLongOpt(OUTPUT_FORMAT_OPT_NAME) .withDescription("Output format: JSON, JSON_LINES, BINARY").hasArg().withArgName("format") .create(OUTPUT_FORMAT_OPT_CHAR); Option inpSchemaOption = OptionBuilder.withLongOpt(INPUT_SCHEMA_OPT_NAME) .withDescription("Input schema file").hasArg().withArgName("file").create(INPUT_SCHEMA_OPT_CHAR); Option outSchemaOption = OptionBuilder.withLongOpt(OUTPUT_SCHEMA_OPT_NAME) .withDescription("Output schema file").hasArg().withArgName("file").create(OUTPUT_SCHEMA_OPT_CHAR); Option inpFileOption = OptionBuilder.withLongOpt(INPUT_FILE_OPT_NAME) .withDescription("input file name or - for STDIN").hasArg().withArgName("file | - ") .create(INPUT_FILE_OPT_CHAR); Option outFileOption = OptionBuilder.withLongOpt(OUTPUT_FILE_OPT_NAME) .withDescription("output file name or - for STDOUT").hasArg().withArgName("file | - ") .create(OUTPUT_FILE_OPT_CHAR); Option verboseOption = OptionBuilder.withDescription("verbose; more occurrences increase verbosity") .create(VERBOSE_OPT_CHAR); _options.addOption(helpOption); _options.addOption(inpFormatOption); _options.addOption(outFormatOption); _options.addOption(inpSchemaOption); _options.addOption(outSchemaOption); _options.addOption(inpFileOption); _options.addOption(outFileOption); _options.addOption(verboseOption); }
From source file:com.conversantmedia.mapreduce.tool.ToolContext.java
@SuppressWarnings("static-access") protected final Options initOptions() { Options options = new Options(); // Help/*from ww w . java 2 s .c o m*/ options.addOption(OptionBuilder.withLongOpt("help").withDescription("Print this help message") .isRequired(false).create('?')); // Required options.addOption(OptionBuilder.withLongOpt(OPTION_INPUT_PATH).withDescription("Input path") .withArgName("path").hasArg().isRequired(true).create('i')); // Optional arguments options.addOption(OptionBuilder.withLongOpt(OPTION_ARCHIVE_PATH) .withDescription("Path to move the input file(s) to following processing.").withArgName("path") .hasArg().isRequired(false).create('a')); options.addOption( OptionBuilder.withLongOpt(OPTION_OUTPUT_PATH).withDescription("Output path for this job's output") .withArgName("path").hasArg().isRequired(false).create('o')); options.addOption(OptionBuilder.withLongOpt(OPTION_DUMP_CONFIG) .withDescription("Dump ALL configuration key/value pairs to STDOUT").isRequired(false).create()); options.addOption(OptionBuilder.withLongOpt(OPTION_DRY_RUN) .withDescription("Performs all setup tasks without executing MR job").isRequired(false).create()); options.addOption(OptionBuilder.withLongOpt(OPTION_SILENT).withDescription("Only output result.") .isRequired(false).create("b")); options.addOption(OptionBuilder.withLongOpt(OPTION_TERSE).withDescription("Output short messages.") .isRequired(false).create("v")); options.addOption(OptionBuilder.withLongOpt(OPTION_VERBOSE).withDescription("Output verbose messages.") .isRequired(false).create("vv")); options.addOption(OptionBuilder.withLongOpt(OPTION_PUBLISH_TSDB_METRIC).withArgName("true|false") .withDescription("Do not publish metrics and throughtputs to Open TSDB.").hasArg().isRequired(false) .create()); options.addOption(OptionBuilder.withLongOpt(OPTION_OPENTSDB_METRIC_NAME) .withDescription("OpenTSDB metric name.").withArgName("name").hasArg().isRequired(false).create()); // For sub-classes initExtraOptions(options); return options; }
From source file:com.google.api.ads.adwords.keywordoptimizer.KeywordOptimizer.java
/** * Creates the command line structure / options. * * @return the command line {@link Options} */// ww w . java 2 s . co m private static Options createCommandLineOptions() { Options options = new Options(); OptionBuilder.withLongOpt("keyword-properties"); OptionBuilder.withDescription("Location of the keyword-optimizer.properties file."); OptionBuilder.hasArg(true); OptionBuilder.withArgName("file"); options.addOption(OptionBuilder.create("kp")); OptionBuilder.withLongOpt("ads-properties"); OptionBuilder.withDescription("Location of the ads.properties file."); OptionBuilder.hasArg(true); OptionBuilder.withArgName("file"); options.addOption(OptionBuilder.create("ap")); OptionBuilder.withLongOpt("help"); OptionBuilder.withDescription("Shows this help screen."); OptionBuilder.withArgName("help"); options.addOption(OptionBuilder.create("h")); OptionBuilder.withLongOpt("seed-keywords"); OptionBuilder.withDescription("Use the given keywords (separated by spaces) as a seed for the optimization." + "\nNote: Only one seed-* option is allowed."); OptionBuilder.hasArg(true); OptionBuilder.hasArgs(Option.UNLIMITED_VALUES); OptionBuilder.withArgName("keywords"); options.addOption(OptionBuilder.create("sk")); OptionBuilder.withLongOpt("seed-keywords-file"); OptionBuilder.withDescription( "Use the keywords from the given file (one keyword per row) as a seed for the optimization." + "\nNote: Only one seed-* option is allowed."); OptionBuilder.hasArg(true); OptionBuilder.withArgName("file"); options.addOption(OptionBuilder.create("skf")); OptionBuilder.withLongOpt("seed-terms"); OptionBuilder .withDescription("Use the given search terms (separated by spaces) as a seed for the optimization." + "\nNote: Only one seed-* option is allowed."); OptionBuilder.hasArg(true); OptionBuilder.hasArgs(Option.UNLIMITED_VALUES); OptionBuilder.withArgName("terms"); options.addOption(OptionBuilder.create("st")); OptionBuilder.withLongOpt("seed-terms-file"); OptionBuilder.withDescription("Use the search terms from the given file (one keyword per row) as a seed " + "for the optimization.\nNote: Only one seed-* option is allowed."); OptionBuilder.hasArg(true); OptionBuilder.withArgName("file"); options.addOption(OptionBuilder.create("stf")); OptionBuilder.withLongOpt("seed-urls"); OptionBuilder.withDescription("Use the given urls (separated by spaces) to extract keywords as a seed for " + "the optimization.\nNote: Only one seed-* option is allowed."); OptionBuilder.hasArg(true); OptionBuilder.hasArgs(Option.UNLIMITED_VALUES); OptionBuilder.withArgName("urls"); options.addOption(OptionBuilder.create("su")); OptionBuilder.withLongOpt("seed-urls-file"); OptionBuilder .withDescription("Use the urls from the given file (one url per row) to extract keywords as a seed " + "for the optimization.\nNote: Only one seed-* option is allowed."); OptionBuilder.hasArg(true); OptionBuilder.withArgName("file"); options.addOption(OptionBuilder.create("suf")); OptionBuilder.withLongOpt("seed-category"); OptionBuilder.withDescription( "Use the given category (ID as defined @ https://goo.gl/xUEr6s) to get keywords as a seed " + "for the optimization.\nNote: Only one seed-* option is allowed."); OptionBuilder.hasArg(true); OptionBuilder.withArgName("id"); options.addOption(OptionBuilder.create("sc")); OptionBuilder.withLongOpt("match-types"); OptionBuilder.withDescription("Use the given keyword match types (EXACT, BROAD, PHRASE)."); OptionBuilder.hasArg(true); OptionBuilder.hasArgs(3); OptionBuilder.withArgName("types"); options.addOption(OptionBuilder.create("m")); OptionBuilder.withLongOpt("max-cpc"); OptionBuilder.withDescription("Use the given maximum CPC (in USD, e.g., 5.0 for $5)."); OptionBuilder.hasArg(true); OptionBuilder.withArgName("double"); options.addOption(OptionBuilder.create("cpc")); OptionBuilder.withLongOpt("locations"); OptionBuilder.withDescription("Use the given locations IDs (ID as defined @ https://goo.gl/TA5E81) for " + "geo-targeted results."); OptionBuilder.hasArg(true); OptionBuilder.hasArgs(Option.UNLIMITED_VALUES); OptionBuilder.withArgName("ids"); options.addOption(OptionBuilder.create("loc")); OptionBuilder.withLongOpt("languages"); OptionBuilder.withDescription("Use the given locations IDs (ID as defined @ https://goo.gl/WWzifs) for " + "language-targeted results."); OptionBuilder.hasArg(true); OptionBuilder.hasArgs(Option.UNLIMITED_VALUES); OptionBuilder.withArgName("ids"); options.addOption(OptionBuilder.create("lang")); OptionBuilder.withLongOpt("output"); OptionBuilder.withDescription("Mode for outputting results (CONSOLE / CSV)\nNote: If set to CSV, then " + "option -of also has to be specified."); OptionBuilder.hasArg(true); OptionBuilder.hasArgs(2); OptionBuilder.withArgName("mode"); options.addOption(OptionBuilder.create("o")); OptionBuilder.withLongOpt("output-file"); OptionBuilder.withDescription("File to for writing output data (only needed if option -o is specified)."); OptionBuilder.hasArg(true); OptionBuilder.withArgName("file"); options.addOption(OptionBuilder.create("of")); return options; }
From source file:com.redhat.rhn.taskomatic.core.TaskomaticDaemon.java
private void createOption(Options accum, String longopt, boolean arg, String argName, String description) { OptionBuilder.withArgName(argName);/*w w w . j ava 2 s.c om*/ OptionBuilder.withLongOpt(longopt); OptionBuilder.hasArg(arg); OptionBuilder.withDescription(description); Option option = OptionBuilder.create(longopt); accum.addOption(option); if (this.masterOptionsMap.get(longopt) == null) { this.masterOptionsMap.put(longopt, option); } }
From source file:ca.uqac.lif.bullwinkle.BullwinkleCli.java
/** * Sets up the options for the command line parser * @return The options//from w w w . j a va 2 s. c o m */ @SuppressWarnings("static-access") private static Options setupOptions() { Options options = new Options(); Option opt; opt = OptionBuilder.withLongOpt("help").withDescription("Display command line usage").create("h"); options.addOption(opt); opt = OptionBuilder.withLongOpt("format").withArgName("x").hasArg() .withDescription("Output parse tree in format x (dot, xml, txt or json). Default: xml").create("f"); options.addOption(opt); opt = OptionBuilder.withLongOpt("verbosity").withArgName("x").hasArg() .withDescription("Verbose messages with level x").create(); options.addOption(opt); return options; }
From source file:eu.planets_project.ifr.core.servreg.utils.client.PlanetsCommand.java
void temp() { // create the command line parser CommandLineParser parser = new PosixParser(); // create the Options Options options = new Options(); options.addOption("a", "all", false, "do not hide entries starting with ."); options.addOption("A", "almost-all", false, "do not list implied . and .."); options.addOption("b", "escape", false, "print octal escapes for nongraphic " + "characters"); options.addOption(OptionBuilder.withLongOpt("block-size").withDescription("use SIZE-byte blocks").hasArg() .withArgName("SIZE").create()); options.addOption("B", "ignore-backups", false, "do not list implied entried " + "ending with ~"); options.addOption("c", false, "with -lt: sort by, and show, ctime (time of last " + "modification of file status information) with " + "-l:show ctime and sort by name otherwise: sort " + "by ctime"); options.addOption("C", false, "list entries by columns"); // automatically generate the help statement HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("mercury", options); String[] args = new String[] { "--block-size=10" }; try {/*from www. j a va2 s . co m*/ // parse the command line arguments CommandLine line = parser.parse(options, args); // validate that block-size has been set if (line.hasOption("block-size")) { // print the value of block-size System.out.println(line.getOptionValue("block-size")); } } catch (ParseException exp) { System.out.println("Unexpected exception:" + exp.getMessage()); } }
From source file:mitm.application.djigzo.tools.CLITool.java
@SuppressWarnings("static-access") private Options createCommandLineOptions() { Options options = new Options(); soapUserOption = OptionBuilder.withLongOpt("soap-user").withDescription("the user for SOAP interface") .hasArg().withArgName("SOAP USER").create(); options.addOption(soapUserOption);/* w ww . jav a2 s . c o m*/ soapPasswordOption = OptionBuilder.withLongOpt("soap-password") .withDescription("the user password for SOAP interface").hasArg().withArgName("SOAP PASSWORD") .create(); options.addOption(soapPasswordOption); loggingOption = OptionBuilder.withLongOpt("logging") .withDescription("If set, debug logging will be enabled").create(); options.addOption(loggingOption); helpOption = OptionBuilder.withLongOpt("help").withDescription("Show help").create(); options.addOption(helpOption); hostOption = OptionBuilder.withLongOpt("host").withArgName("HOSTNAME | IP").hasArg() .withDescription("The host to connect to (127.0.0.1)").create(); options.addOption(hostOption); portOption = OptionBuilder.withLongOpt("port").withArgName("PORT").hasArg() .withDescription("The port to use (" + DjigzoWSDefaults.PORT + ")").create(); options.addOption(portOption); setPropertyOption = OptionBuilder.withLongOpt("set-property").withDescription("Sets a property").hasArg() .withArgName("PROPERTY NAME").create(); options.addOption(setPropertyOption); getPropertyOption = OptionBuilder.withLongOpt("get-property").withDescription("Returns a property value") .hasArg().withArgName("PROPERTY NAME").create(); options.addOption(getPropertyOption); valueOption = OptionBuilder.withLongOpt("value").withDescription("The value to set").hasArg() .withArgName("VALUE").create(); options.addOption(valueOption); encryptOption = OptionBuilder.withLongOpt("encrypt") .withDescription("If set, the property is an encrypted property").create(); options.addOption(encryptOption); emailOption = OptionBuilder.withLongOpt("email").withDescription("The email address of the user").hasArg() .withArgName("EMAIL").create(); options.addOption(emailOption); domainOption = OptionBuilder.withLongOpt("domain").withDescription("The domain").hasArg() .withArgName("DOMAIN").create(); options.addOption(domainOption); addUserOption = OptionBuilder.withLongOpt("add-user").withDescription("Add a user").hasArg() .withArgName("EMAIL").create(); options.addOption(addUserOption); deleteUserOption = OptionBuilder.withLongOpt("delete-user").withDescription("Delete a user").hasArg() .withArgName("EMAIL").create(); options.addOption(deleteUserOption); addDomainOption = OptionBuilder.withLongOpt("add-domain").withDescription("Add a domain").hasArg() .withArgName("DOMAIN").create(); options.addOption(addDomainOption); deleteDomainOption = OptionBuilder.withLongOpt("delete-domain").withDescription("Delete a domain").hasArg() .withArgName("DOMAIN").create(); options.addOption(deleteDomainOption); globalOption = OptionBuilder.withLongOpt("global").withDescription("Set/Get the global options").create(); options.addOption(globalOption); importXMLOption = OptionBuilder.withLongOpt("import-xml") .withDescription("Import users and domains from XML").hasArg().withArgName("XML FILE").create(); options.addOption(importXMLOption); encodePasswordOption = OptionBuilder.withLongOpt("encode-password") .withDescription("Encodes a portal password").hasArg().withArgName("PASSWORD").create(); options.addOption(encodePasswordOption); saltOption = OptionBuilder.withLongOpt("salt") .withDescription("Optional salt used for encoding a portal password").hasArg().withArgName("SALT") .create(); options.addOption(saltOption); return options; }
From source file:net.sourceforge.czt.gnast.Gnast.java
/** * Parses the arguments from the command line. * * @return a configured GnAST builder if parsing was successful; * {@code null} otherwise./*from www. j a v a 2s . co m*/ * @throws NullPointerException if {@code args} is {@code null} */ @SuppressWarnings("static-access") private static GnastBuilder parseArguments(String[] args) { Options argOptions = new Options(); OptionGroup verboseOptions = new OptionGroup(); verboseOptions.addOption(OptionBuilder.withLongOpt("verbose") .withDescription("Verbose; display verbose debugging messages").create("v")); verboseOptions.addOption(OptionBuilder.withLongOpt("vverbose") .withDescription("Very verbose; more verbose debugging messages").create("vv")); verboseOptions.addOption(OptionBuilder.withLongOpt("vvverbose") .withDescription("Very very verbose; even more verbose debugging messages").create("vvv")); argOptions.addOptionGroup(verboseOptions); argOptions.addOption(OptionBuilder.withLongOpt("finalizers") .withDescription("Add AST finalisers. WARNING: ASTs will consume more memory!").create("f")); argOptions.addOption(OptionBuilder.withArgName("dir").hasArg().withLongOpt("destination") .withDescription("Generated files go into this directory").create("d")); argOptions.addOption(OptionBuilder.withArgName("dir1 dir2").hasArgs().withValueSeparator(',') .withLongOpt("templates").withDescription("Additional template directories").create("t")); argOptions.addOption(OptionBuilder.withArgName("file").hasArg().withLongOpt("mapping") .withDescription("XML type mapping properties file").create("m")); argOptions.addOption(OptionBuilder.withArgName("dir").hasArg().withLongOpt("source").withDescription( "The directory with all ZML schema files. The requested project namespace must be present, as well as all its parents.") .create("s")); argOptions.addOption(OptionBuilder.withArgName("url").hasArg().withLongOpt("namespace") .withDescription("The namespace of the project to be generated.").create("n")); // use GNU parser that allows longer option name (e.g. `-vvv`) CommandLineParser parser = new GnuParser(); CommandLine line; try { // parse the command line arguments line = parser.parse(argOptions, args); } catch (ParseException exp) { // oops, something went wrong System.err.println(exp.getMessage()); // automatically generate the help statement HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("gnast", argOptions, true); return null; } Level verbosity = line.hasOption("v") ? Level.INFO : (line.hasOption("vv") ? Level.FINE : (line.hasOption("vvv") ? Level.FINER : Level.OFF)); String[] templates = line.getOptionValues("t"); List<URL> templateDirs = new ArrayList<URL>(); for (String path : templates) { templateDirs.add(toURL(path)); } return new GnastBuilder().verbosity(verbosity).finalizers(line.hasOption("f")) .destination(toFile(line.getOptionValue("d"))).templates(templateDirs) .mapping(toURL(line.getOptionValue("m"))).sourceSchemas(schemaDirToURL(line.getOptionValue("s"))) .namespace(line.getOptionValue("n")); }
From source file:com.symbian.utils.cmdline.CmdLine.java
/** * Adds a switch to a command./* w w w . j av a 2s. c om*/ * * @param aSwitchName * name of the switch * @param aIsSingle * If the switch is single. * @param aDescription * description of the switch (for help command) * @param aIsMandatory * make switch mandatory * @param aDataCheck * facility to check the validity of the parameter. */ public synchronized void addSwitch(final String aSwitchName, final boolean aIsSingle, final String aDescription, final boolean aIsMandatory, final DataAcceptable aDataCheck) { Option lOption = null; OptionBuilder.withArgName(aSwitchName); OptionBuilder.withDescription(aDescription); OptionBuilder.isRequired(aIsMandatory); OptionBuilder.hasArg(aDataCheck != null); if (!aIsSingle) { OptionBuilder.withLongOpt(aSwitchName); lOption = OptionBuilder.create(); } else { lOption = OptionBuilder.create(aSwitchName); } if (aDataCheck != null) { iParametersToCheck.add(aSwitchName); iParametersChecks.add(aDataCheck); } iOptions.addOption(lOption); }
From source file:com.github.errantlinguist.latticevisualiser.ArgParser.java
/** * Creates and adds a horizontal size option to a given {@link Options} * object./*from ww w. j av a 2 s . c om*/ * * @param options * The <code>Options</code> object to add to. */ private static void addXSizeOption(final Options options) { OptionBuilder.withLongOpt(WIDTH_KEY_LONG); OptionBuilder.withDescription(WIDTH_DESCR); OptionBuilder.hasArg(); OptionBuilder.withArgName(SIZE_ARG_NAME); OptionBuilder.withType(Integer.class); final Option width = OptionBuilder.create(WIDTH_KEY); options.addOption(width); }