List of usage examples for org.apache.commons.cli OptionBuilder isRequired
public static OptionBuilder isRequired(boolean newRequired)
required
is true. From source file:org.apache.nutch.tools.CommonCrawlDataDumper.java
@Override public int run(String[] args) throws Exception { Option helpOpt = new Option("h", "help", false, "show this help message."); // argument options @SuppressWarnings("static-access") Option outputOpt = OptionBuilder.withArgName("outputDir").hasArg() .withDescription("output directory (which will be created) to host the CBOR data.") .create("outputDir"); // WARC format Option warcOpt = new Option("warc", "export to a WARC file"); @SuppressWarnings("static-access") Option segOpt = OptionBuilder.withArgName("segment").hasArgs() .withDescription("the segment or directory containing segments to use").create("segment"); // create mimetype and gzip options @SuppressWarnings("static-access") Option mimeOpt = OptionBuilder.isRequired(false).withArgName("mimetype").hasArgs() .withDescription("an optional list of mimetypes to dump, excluding all others. Defaults to all.") .create("mimetype"); @SuppressWarnings("static-access") Option gzipOpt = OptionBuilder.withArgName("gzip").hasArg(false) .withDescription("an optional flag indicating whether to additionally gzip the data.") .create("gzip"); @SuppressWarnings("static-access") Option keyPrefixOpt = OptionBuilder.withArgName("keyPrefix").hasArg(true) .withDescription("an optional prefix for key in the output format.").create("keyPrefix"); @SuppressWarnings("static-access") Option simpleDateFormatOpt = OptionBuilder.withArgName("SimpleDateFormat").hasArg(false) .withDescription("an optional format for timestamp in GMT epoch milliseconds.") .create("SimpleDateFormat"); @SuppressWarnings("static-access") Option epochFilenameOpt = OptionBuilder.withArgName("epochFilename").hasArg(false) .withDescription("an optional format for output filename.").create("epochFilename"); @SuppressWarnings("static-access") Option jsonArrayOpt = OptionBuilder.withArgName("jsonArray").hasArg(false) .withDescription("an optional format for JSON output.").create("jsonArray"); @SuppressWarnings("static-access") Option reverseKeyOpt = OptionBuilder.withArgName("reverseKey").hasArg(false) .withDescription("an optional format for key value in JSON output.").create("reverseKey"); @SuppressWarnings("static-access") Option extensionOpt = OptionBuilder.withArgName("extension").hasArg(true) .withDescription("an optional file extension for output documents.").create("extension"); @SuppressWarnings("static-access") Option sizeOpt = OptionBuilder.withArgName("warcSize").hasArg(true).withType(Number.class) .withDescription("an optional file size in bytes for the WARC file(s)").create("warcSize"); @SuppressWarnings("static-access") Option linkDbOpt = OptionBuilder.withArgName("linkdb").hasArg(true) .withDescription("an optional linkdb parameter to include inlinks in dump files").isRequired(false) .create("linkdb"); // create the options Options options = new Options(); options.addOption(helpOpt);// w w w. j a va 2s . co m options.addOption(outputOpt); options.addOption(segOpt); // create mimetypes and gzip options options.addOption(warcOpt); options.addOption(mimeOpt); options.addOption(gzipOpt); // create keyPrefix option options.addOption(keyPrefixOpt); // create simpleDataFormat option options.addOption(simpleDateFormatOpt); options.addOption(epochFilenameOpt); options.addOption(jsonArrayOpt); options.addOption(reverseKeyOpt); options.addOption(extensionOpt); options.addOption(sizeOpt); options.addOption(linkDbOpt); CommandLineParser parser = new GnuParser(); try { CommandLine line = parser.parse(options, args); if (line.hasOption("help") || !line.hasOption("outputDir") || (!line.hasOption("segment"))) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(CommonCrawlDataDumper.class.getName(), options, true); return 0; } File outputDir = new File(line.getOptionValue("outputDir")); File segmentRootDir = new File(line.getOptionValue("segment")); String[] mimeTypes = line.getOptionValues("mimetype"); boolean gzip = line.hasOption("gzip"); boolean epochFilename = line.hasOption("epochFilename"); String keyPrefix = line.getOptionValue("keyPrefix", ""); boolean simpleDateFormat = line.hasOption("SimpleDateFormat"); boolean jsonArray = line.hasOption("jsonArray"); boolean reverseKey = line.hasOption("reverseKey"); String extension = line.getOptionValue("extension", ""); boolean warc = line.hasOption("warc"); long warcSize = 0; if (line.getParsedOptionValue("warcSize") != null) { warcSize = (Long) line.getParsedOptionValue("warcSize"); } String linkdbPath = line.getOptionValue("linkdb"); File linkdb = linkdbPath == null ? null : new File(linkdbPath); CommonCrawlConfig config = new CommonCrawlConfig(); config.setKeyPrefix(keyPrefix); config.setSimpleDateFormat(simpleDateFormat); config.setJsonArray(jsonArray); config.setReverseKey(reverseKey); config.setCompressed(gzip); config.setWarcSize(warcSize); config.setOutputDir(line.getOptionValue("outputDir")); if (!outputDir.exists()) { LOG.warn("Output directory: [" + outputDir.getAbsolutePath() + "]: does not exist, creating it."); if (!outputDir.mkdirs()) throw new Exception("Unable to create: [" + outputDir.getAbsolutePath() + "]"); } CommonCrawlDataDumper dumper = new CommonCrawlDataDumper(config); dumper.dump(outputDir, segmentRootDir, linkdb, gzip, mimeTypes, epochFilename, extension, warc); } catch (Exception e) { LOG.error(CommonCrawlDataDumper.class.getName() + ": " + StringUtils.stringifyException(e)); e.printStackTrace(); return -1; } return 0; }
From source file:org.apache.openejb.util.ListSetters.java
public static void main(final String[] args) throws Exception { final Options options = new Options(); options.addOption(OptionBuilder.isRequired(true).hasArg(true).withLongOpt("class") .withDescription("the class to introspect").create("c")); final CommandLine line; try {//from w ww .j a v a 2s. c o m line = new PosixParser().parse(options, args); } catch (final ParseException exp) { help(options); throw new SystemExitException(-1); } if (line.hasOption("help")) { help(options); return; } final String clazz = line.getOptionValue("class"); final Collection<Class<?>> ancestors = Classes .ancestors(Thread.currentThread().getContextClassLoader().loadClass(clazz)); final List<String> list = new LinkedList<>(); for (final Class<?> c : ancestors) { for (final Method m : c.getDeclaredMethods()) { if (!Modifier.isPublic(m.getModifiers())) { continue; } if (!m.getName().startsWith("set")) { continue; } if (m.getGenericParameterTypes().length != 1) { continue; } list.add(m.getName().substring(3)); } } Collections.sort(list); for (final String s : list) { System.out.println("- " + s); } }
From source file:org.apache.usergrid.launcher.Server.java
static Options createOptions() { // the nogui option will be required due to combining the graphical // launcher with this standalone CLI based server Options options = new Options(); OptionBuilder.withDescription("Start launcher without UI"); OptionBuilder.isRequired(true); Option noguiOption = OptionBuilder.create("nogui"); OptionBuilder.isRequired(false);/*from w ww .j a va 2 s .c om*/ OptionBuilder.withDescription("Initialize database"); Option initOption = OptionBuilder.create("init"); OptionBuilder.withDescription("Start database"); Option dbOption = OptionBuilder.create("db"); OptionBuilder.withDescription("Http port (without UI)"); OptionBuilder.hasArg(); OptionBuilder.withArgName("PORT"); OptionBuilder.withLongOpt("port"); OptionBuilder.withType(Number.class); Option portOption = OptionBuilder.create('p'); options.addOption(initOption); options.addOption(dbOption); options.addOption(portOption); options.addOption(noguiOption); return options; }
From source file:org.apache.wink.example.googledocs.CLIHelper.java
@SuppressWarnings("static-access") public CLIHelper() { Option userOption = OptionBuilder.withArgName("user").hasArg() .withDescription("Full username. Example: user@gmail.com").isRequired(true).withLongOpt("user") .create(USER_OPT);//from ww w. j ava 2 s . c o m Option passwordOption = OptionBuilder.withArgName("password").isRequired(true).hasArg() .withDescription("Password").withLongOpt("password").create(PASSWORD_OPT); Option uploadFileOption = OptionBuilder.withArgName("file").isRequired(false).hasArg() .withDescription("Path to a file to upload").withLongOpt("upload").create(UPLOAD_FILE_OPT); Option listFilesOption = OptionBuilder.hasArg(false).withDescription("List files").withLongOpt("list") .create(LIST_OPT); Option deleteOption = OptionBuilder.withArgName("document id").hasArg(true) .withDescription("Delete document. Use --list to get a document id.").withLongOpt("delete") .create(DELETE_OPT); Option proxyHostOption = OptionBuilder.isRequired(false).withArgName("host").hasArg(true) .withDescription("Proxy host").withLongOpt("proxy").create(PROXY_HOST_ORT); Option proxyPortOption = OptionBuilder.isRequired(false).withArgName("port").hasArg(true) .withDescription("Proxy port").withLongOpt("port").create(PROXY_PORT_OPT); OptionGroup group = new OptionGroup(); group.setRequired(true); group.addOption(uploadFileOption); group.addOption(listFilesOption); group.addOption(deleteOption); options.addOptionGroup(group); options.addOption(proxyHostOption); options.addOption(proxyPortOption); options.addOption(passwordOption); options.addOption(userOption); }
From source file:org.controlhaus.webservice.generator.ExtensionMaker.java
private static Options buildOptions() { Options options = new Options(); OptionBuilder.hasArg();/*from ww w. j a v a2s . co m*/ OptionBuilder.withArgName("dir"); OptionBuilder.withDescription("Base directory of the wsdl file(s)"); OptionBuilder.isRequired(true); Option option = OptionBuilder.create("wsdl"); options.addOption(option); OptionBuilder.hasArg(); OptionBuilder.withArgName("dir"); OptionBuilder.withDescription("Root directory for the jcx file."); OptionBuilder.isRequired(true); option = OptionBuilder.create("gen_root"); options.addOption(option); // OptionBuilder.hasArg(); // OptionBuilder.withArgName("URL"); // OptionBuilder.withDescription("URL to the web service."); // option = OptionBuilder.create("serviceURL"); // OptionBuilder.isRequired(false); // if specified, it will overwrite // // the one in WSDL // options.addOption(option); OptionBuilder.hasArg(); OptionBuilder.withArgName("dir"); OptionBuilder.isRequired(false); OptionBuilder.withDescription("path annotation to use in the jcx"); option = OptionBuilder.create("wsdl_path_annotation"); options.addOption(option); OptionBuilder.hasArg(); OptionBuilder.withArgName("package_name"); OptionBuilder.isRequired(false); OptionBuilder.withDescription("Package name of the jcx"); option = OptionBuilder.create("pkg"); options.addOption(option); return options; }
From source file:org.dspace.discovery.IndexClient.java
/** * When invoked as a command-line tool, creates, updates, removes content * from the whole index//from w ww .jav a 2s . c om * * @param args the command-line arguments, none used * @throws java.io.IOException * @throws java.sql.SQLException * */ public static void main(String[] args) throws SQLException, IOException, SearchServiceException { Context context = new Context(); context.setIgnoreAuthorization(true); String usage = "org.dspace.discovery.IndexClient [-cbhf[r <item handle>]] or nothing to update/clean an existing index."; Options options = new Options(); HelpFormatter formatter = new HelpFormatter(); CommandLine line = null; options.addOption(OptionBuilder.withArgName("item handle").hasArg(true) .withDescription("remove an Item, Collection or Community from index based on its handle") .create("r")); options.addOption(OptionBuilder.isRequired(false) .withDescription("clean existing index removing any documents that no longer exist in the db") .create("c")); options.addOption(OptionBuilder.isRequired(false) .withDescription("(re)build index, wiping out current one if it exists").create("b")); options.addOption(OptionBuilder.isRequired(false) .withDescription("if updating existing index, force each handle to be reindexed even if uptodate") .create("f")); options.addOption(OptionBuilder.isRequired(false).withDescription("print this help message").create("h")); options.addOption(OptionBuilder.isRequired(false).withDescription("optimize search core").create("o")); try { line = new PosixParser().parse(options, args); } catch (Exception e) { // automatically generate the help statement formatter.printHelp(usage, e.getMessage(), options, ""); System.exit(1); } if (line.hasOption("h")) { // automatically generate the help statement formatter.printHelp(usage, options); System.exit(1); } /** Acquire from dspace-services in future */ /** * new DSpace.getServiceManager().getServiceByName("org.dspace.discovery.SolrIndexer"); */ DSpace dspace = new DSpace(); IndexingService indexer = dspace.getServiceManager().getServiceByName(IndexingService.class.getName(), IndexingService.class); if (line.hasOption("r")) { log.info("Removing " + line.getOptionValue("r") + " from Index"); indexer.unIndexContent(context, line.getOptionValue("r")); } else if (line.hasOption("c")) { log.info("Cleaning Index"); indexer.cleanIndex(line.hasOption("f")); } else if (line.hasOption("b")) { log.info("(Re)building index from scratch."); indexer.createIndex(context); } else if (line.hasOption("o")) { log.info("Optimizing search core."); indexer.optimize(); } else { log.info("Updating and Cleaning Index"); indexer.cleanIndex(line.hasOption("f")); indexer.updateIndex(context, line.hasOption("f")); } log.info("Done with indexing"); }
From source file:org.dspace.search.DSIndexer.java
/** * When invoked as a command-line tool, creates, updates, removes * content from the whole index//from w w w. ja v a 2 s.c o m * * @param args * the command-line arguments, none used * @throws IOException * @throws SQLException */ public static void main(String[] args) throws SQLException, IOException { Date startTime = new Date(); try { setBatchProcessingMode(true); Context context = new Context(); context.setIgnoreAuthorization(true); String usage = "org.dspace.search.DSIndexer [-cbhof[r <item handle>]] or nothing to update/clean an existing index."; Options options = new Options(); HelpFormatter formatter = new HelpFormatter(); CommandLine line = null; options.addOption(OptionBuilder.withArgName("item handle").hasArg(true) .withDescription("remove an Item, Collection or Community from index based on its handle") .create("r")); options.addOption( OptionBuilder.isRequired(false).withDescription("optimize existing index").create("o")); options.addOption(OptionBuilder.isRequired(false) .withDescription("clean existing index removing any documents that no longer exist in the db") .create("c")); options.addOption(OptionBuilder.isRequired(false) .withDescription("(re)build index, wiping out current one if it exists").create("b")); options.addOption(OptionBuilder.isRequired(false) .withDescription( "if updating existing index, force each handle to be reindexed even if uptodate") .create("f")); options.addOption( OptionBuilder.isRequired(false).withDescription("print this help message").create("h")); try { line = new PosixParser().parse(options, args); } catch (Exception e) { // automatically generate the help statement formatter.printHelp(usage, e.getMessage(), options, ""); System.exit(1); } if (line.hasOption("h")) { // automatically generate the help statement formatter.printHelp(usage, options); System.exit(1); } if (line.hasOption("r")) { log.info("Removing " + line.getOptionValue("r") + " from Index"); unIndexContent(context, line.getOptionValue("r")); } else if (line.hasOption("o")) { log.info("Optimizing Index"); optimizeIndex(context); } else if (line.hasOption("c")) { log.info("Cleaning Index"); cleanIndex(context); } else if (line.hasOption("b")) { log.info("(Re)building index from scratch."); createIndex(context); } else { log.info("Updating and Cleaning Index"); cleanIndex(context); updateIndex(context, line.hasOption("f")); } log.info("Done with indexing"); } finally { setBatchProcessingMode(false); Date endTime = new Date(); System.out.println("Started: " + startTime.getTime()); System.out.println("Ended: " + endTime.getTime()); System.out.println("Elapsed time: " + ((endTime.getTime() - startTime.getTime()) / 1000) + " secs (" + (endTime.getTime() - startTime.getTime()) + " msecs)"); } }
From source file:org.easyrec.plugin.cli.AbstractGeneratorCLI.java
protected AbstractGeneratorCLI() { options = new Options(); OptionBuilder optionBuilder = OptionBuilder.withArgName("tenants"); optionBuilder.withLongOpt("tenant"); optionBuilder.isRequired(false); optionBuilder.hasArg(true);//w ww . ja va2s. co m optionBuilder.withDescription( "Specifiy a tenant to generate rules for. Ranges can be specified e.g. 1 - 3 will generate rules for tenants 1 to 3. Alternatively you can specify a list of tenants like 1,2,4. If omitted rules for all tenants are generated."); Option tenantOption = optionBuilder.create('t'); optionBuilder = OptionBuilder.withLongOpt("uninstall"); optionBuilder.isRequired(false); optionBuilder.hasArg(false); optionBuilder.withDescription("When true the generator is uninstalled when execution finished"); Option uninstallOption = optionBuilder.create('u'); options.addOption(tenantOption); options.addOption(uninstallOption); }
From source file:org.eu.eark.textclassification.TextClassifierJob.java
@SuppressWarnings("static-access") protected int parseArgs(String[] args) { Options cliOptions = new Options(); Option tableOption = OptionBuilder.isRequired(false).withArgName("table name").hasArg() .withDescription("Lily table name").withLongOpt("table").create("t"); cliOptions.addOption(tableOption);//from w w w . j a v a 2 s. c om Option zkOption = OptionBuilder.isRequired().withArgName("connection-string").hasArg() .withDescription("ZooKeeper connection string: hostname1:port,hostname2:port,...") .withLongOpt("zookeeper").create("z"); cliOptions.addOption(zkOption); // command line parameters (all mandatory) for text classification: // -i: a file that contains on every line <path>,<application/type> for every Lily object that should be classified - must be on HDFS! Option inputOption = OptionBuilder.isRequired().withArgName("input").hasArg() .withDescription("File with paths and contentTypes (as saved in Lily)").withLongOpt("input") .create("i"); cliOptions.addOption(inputOption); // -c: the python file containing the classifier that will be used (requires a path on the local filesystem) Option classifierOption = OptionBuilder.isRequired().withArgName("classifier script").hasArg() .withDescription("path to Python classifier script").withLongOpt("pyclf").create("c"); cliOptions.addOption(classifierOption); // -m: the model used for classification (requires a path on the local filesystem, to <model>.pkl - all other .pkl files for this model must be in the same folder) Option modelOption = OptionBuilder.isRequired().withArgName("model").hasArg() .withDescription("path to model").withLongOpt("model").create("m"); cliOptions.addOption(modelOption); CommandLineParser parser = new PosixParser(); CommandLine cmd; try { cmd = parser.parse(cliOptions, args); } catch (ParseException e) { System.out.println(e.getMessage()); System.out.println(); HelpFormatter help = new HelpFormatter(); help.printHelp(getClass().getSimpleName(), cliOptions, true); return 1; } tableName = cmd.getOptionValue(tableOption.getOpt()); zkConnectString = cmd.getOptionValue(zkOption.getOpt()); inputFile = cmd.getOptionValue(inputOption.getOpt()); classifier = cmd.getOptionValue(classifierOption.getOpt()); model = cmd.getOptionValue(modelOption.getOpt()); return 0; }
From source file:org.inbio.neoportal.index.Indexer.java
/** * Process the arguments that comes from the console. * /*from www. j a v a 2 s . com*/ * @param args [action, search terms] * @throws InterruptedException */ @SuppressWarnings("static-access") public void processArguments(String[] args) throws InterruptedException { // configure the command line options Options options = new Options(); options.addOption(OptionBuilder.withArgName("class to index").hasArgs(1) .withDescription( "Index an entity (all|Taxon|CommonName|TaxonDescription|GeoFeature|Location|Occurrences)") .create("index")); options.addOption(OptionBuilder.withArgName("csvFile").hasArgs(1) .withDescription("Import and index taxonomy").create("t")); options.addOption(OptionBuilder.withArgName("csvFile").hasArgs(1) .withDescription("Import and index occurrences").create("o")); options.addOption(OptionBuilder.isRequired(false).withDescription("Index occurrences from import_dwc table") .withLongOpt("dwc-index").create()); options.addOption(OptionBuilder.isRequired(false).withDescription("Just insert records, do not run indexer") .withLongOpt("insert-only").create()); try { CommandLineParser parser = new org.apache.commons.cli.GnuParser(); CommandLine cmd = parser.parse(options, args); // execute the appropriate functions if (cmd.hasOption("index")) { String entityName = cmd.getOptionValue("index"); this.createIndex(entityName); // System.out.println("option index"); } else if (cmd.hasOption("t")) { String csvFile = cmd.getOptionValue("t"); importer.importTaxonomy(csvFile); if (!cmd.hasOption("insert-only")) createIndex("Taxon"); // System.out.println("option t"); } else if (cmd.hasOption("o")) { String csvFile = cmd.getOptionValue("o"); // importer.importIndexOccurrences(csvFile); importer.importDwcOccurrences(csvFile); importer.indexOccurrences(); } else if (cmd.hasOption("dwc-index")) { importer.indexOccurrences(); } else { // automatically generate the help statement HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("indexer", options); } // Importer importer = new Importer(); // importer.importOccurrences(); // importer.importAll( // "/home/arturo/Proyectos/atta2-portal/AttaExport/GeoCapas/AttaGeoLayersFromSnaps_v03.csv", // "/home/arturo/Proyectos/atta2-portal/AttaExport/GeoCapas/AttaProvincias.csv", // "/home/arturo/Proyectos/atta2-portal/AttaExport/GeoCapas/AttaGeoSitesFromSnaps_v03.csv", // "/home/arturo/Proyectos/atta2-portal/AttaExport/ubis_20120518_2.csv"); } catch (org.apache.commons.cli.ParseException e) { System.out.print("Parse error: "); System.out.println(e.getMessage()); // automatically generate the help statement HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("indexer", options); } }