List of usage examples for org.apache.commons.cli Option Option
public Option(String opt, String description) throws IllegalArgumentException
From source file:eu.fbk.dkm.sectionextractor.pantheon.WikipediaGoodTextExtractor.java
public static void main(String args[]) throws IOException { CommandLineWithLogger commandLineWithLogger = new CommandLineWithLogger(); commandLineWithLogger.addOption(OptionBuilder.withArgName("file").hasArg() .withDescription("wikipedia xml dump file").isRequired().withLongOpt("wikipedia-dump").create("d")); commandLineWithLogger.addOption(OptionBuilder.withArgName("dir").hasArg() .withDescription("output directory in which to store output files").isRequired() .withLongOpt("output-dir").create("o")); commandLineWithLogger/*ww w.j a v a 2 s . co m*/ .addOption(OptionBuilder.withDescription("use NAF format").withLongOpt("naf").create("n")); commandLineWithLogger.addOption(OptionBuilder.withDescription("tokenize and ssplit with Stanford") .withLongOpt("stanford").create("s")); commandLineWithLogger.addOption(OptionBuilder.withArgName("file").hasArg().withDescription("Filter file") .withLongOpt("filter").create("f")); commandLineWithLogger.addOption(OptionBuilder.withArgName("file").hasArg() .withDescription("ID and category file").withLongOpt("idcat").create("i")); commandLineWithLogger.addOption(OptionBuilder.withArgName("file").hasArg().withDescription("Redirect file") .withLongOpt("redirect").create("r")); commandLineWithLogger.addOption(OptionBuilder.withArgName("int").hasArg() .withDescription( "number of threads (default " + AbstractWikipediaXmlDumpParser.DEFAULT_THREADS_NUMBER + ")") .withLongOpt("num-threads").create("t")); commandLineWithLogger.addOption(OptionBuilder.withArgName("int").hasArg() .withDescription("number of pages to process (default all)").withLongOpt("num-pages").create("p")); commandLineWithLogger.addOption(OptionBuilder.withArgName("int").hasArg() .withDescription("receive notification every n pages (default " + AbstractWikipediaExtractor.DEFAULT_NOTIFICATION_POINT + ")") .withLongOpt("notification-point").create("b")); commandLineWithLogger.addOption(new Option("n", "NAF format")); CommandLine commandLine = null; try { commandLine = commandLineWithLogger.getCommandLine(args); PropertyConfigurator.configure(commandLineWithLogger.getLoggerProps()); } catch (Exception e) { System.exit(1); } int numThreads = Integer.parseInt(commandLine.getOptionValue("num-threads", Integer.toString(AbstractWikipediaXmlDumpParser.DEFAULT_THREADS_NUMBER))); int numPages = Integer.parseInt(commandLine.getOptionValue("num-pages", Integer.toString(AbstractWikipediaExtractor.DEFAULT_NUM_PAGES))); int notificationPoint = Integer.parseInt(commandLine.getOptionValue("notification-point", Integer.toString(AbstractWikipediaExtractor.DEFAULT_NOTIFICATION_POINT))); boolean nafFormat = commandLine.hasOption("n"); boolean useStanford = commandLine.hasOption("s"); HashMap<Integer, String> idCategory = new HashMap<>(); String idcatFileName = commandLine.getOptionValue("idcat"); if (idcatFileName != null) { logger.info("Loading categories"); File idcatFile = new File(idcatFileName); if (idcatFile.exists()) { List<String> lines = Files.readLines(idcatFile, Charsets.UTF_8); for (String line : lines) { line = line.trim(); if (line.length() == 0) { continue; } String[] parts = line.split("\\s+"); if (parts.length < 3) { continue; } idCategory.put(Integer.parseInt(parts[1]), parts[2]); } } } HashMap<String, String> redirects = new HashMap<>(); String redirectFileName = commandLine.getOptionValue("redirect"); if (redirectFileName != null) { logger.info("Loading redirects"); File redirectFile = new File(redirectFileName); if (redirectFile.exists()) { List<String> lines = Files.readLines(redirectFile, Charsets.UTF_8); for (String line : lines) { line = line.trim(); if (line.length() == 0) { continue; } String[] parts = line.split("\\t+"); if (parts.length < 2) { continue; } redirects.put(parts[0], parts[1]); } } } HashSet<String> pagesToConsider = null; String filterFileName = commandLine.getOptionValue("filter"); if (filterFileName != null) { logger.info("Loading file list"); File filterFile = new File(filterFileName); if (filterFile.exists()) { pagesToConsider = new HashSet<>(); List<String> lines = Files.readLines(filterFile, Charsets.UTF_8); for (String line : lines) { line = line.trim(); if (line.length() == 0) { continue; } line = line.replaceAll("\\s+", "_"); pagesToConsider.add(line); addRedirects(pagesToConsider, redirects, line, 0); } } } ExtractorParameters extractorParameters = new ExtractorParameters( commandLine.getOptionValue("wikipedia-dump"), commandLine.getOptionValue("output-dir")); File outputFolder = new File(commandLine.getOptionValue("output-dir")); if (!outputFolder.exists()) { boolean mkdirs = outputFolder.mkdirs(); if (!mkdirs) { throw new IOException("Unable to create folder " + outputFolder.getAbsolutePath()); } } WikipediaExtractor wikipediaPageParser = new WikipediaGoodTextExtractor(numThreads, numPages, extractorParameters.getLocale(), outputFolder, nafFormat, pagesToConsider, useStanford, idCategory); wikipediaPageParser.setNotificationPoint(notificationPoint); wikipediaPageParser.start(extractorParameters); logger.info("extraction ended " + new Date()); }
From source file:com.denimgroup.threadfix.cli.OptionsHolder.java
@SuppressWarnings("static-access") public static Options getOptions() { Options options = new Options(); Option property = OptionBuilder.withArgName("unsafe-ssl").hasArgs(1).withValueSeparator() .withDescription("unsafe-ssl to force ThreadFix to accept unsigned certificates.").create("D"); options.addOption(property);/*from ww w.ja va2 s. c o m*/ Option teams = OptionBuilder.withLongOpt("teams") .withDescription("Fetches a list of ThreadFix teams and applications.").create("t"); options.addOption(teams); Option teamsPrettyPrint = OptionBuilder.withLongOpt("teamsPrettyPrint") .withDescription( "Fetches a human readable list of ThreadFix teams, applications, and application IDs.") .create("tpp"); options.addOption(teamsPrettyPrint); options.addOption(new Option("help", "Print this message")); Option set = OptionBuilder.withArgName("property> <value").hasArgs(2).withLongOpt("set") .withDescription("Set either the url (ThreadFix base url) or key (ThreadFix API key) properties") .create("s"); options.addOption(set); Option search = OptionBuilder.hasOptionalArgs().withLongOpt("vulnerabilitySearch").withDescription( "Query the vulnerabilities using various optional parameters. More information can " + "be found at https://github.com/denimgroup/threadfix/wiki/Threadfix-REST-Interface") .create("search"); options.addOption(search); Option queueScan = OptionBuilder.withArgName("applicationId> <scannerName> <[scan profile Id]").hasArgs(3) .withLongOpt("queueScan") .withDescription("Queue a scan for the given applicationId with the given scanner type") .create("q"); options.addOption(queueScan); Option addAppUrl = OptionBuilder.withArgName("applicationId> <appUrl").hasArgs(2).withLongOpt("addAppUrl") .withDescription("Add URL for the given applicationId").create("au"); options.addOption(addAppUrl); Option setTaskConfig = OptionBuilder.withArgName("applicationId> <scannerName> <file").hasArgs(3) .withLongOpt("setTaskConfig") .withDescription( "Save the scan configuration for the given applicationId with the given scanner type") .create("stc"); options.addOption(setTaskConfig); Option setParameters = OptionBuilder.withArgName("appId> <frameworkType> <repositoryUrl").hasArgs(3) .withLongOpt("setParameters") .withDescription("Set scan parameters. Available parameters can be found with --printScanOptions") .create("sp"); options.addOption(setParameters); options.addOption(new Option("printScanOptions", "Prints available scan options")); options.addOption(new Option("printScannerNames", "Prints scanner names supported by ScanAgent")); Option createTeam = OptionBuilder.withArgName("name").hasArg().withLongOpt("create-team") .withDescription("Creates a ThreadFix team and returns its JSON.").create("ct"); options.addOption(createTeam); Option createApp = OptionBuilder.withArgName("teamId> <name> <url").hasArgs(3).withLongOpt("create-app") .withDescription("Creates a ThreadFix application and returns its JSON.").create("ca"); options.addOption(createApp); Option createWaf = OptionBuilder.withArgName("name> <wafTypeName").hasArgs(2).withLongOpt("create-waf") .withDescription("Creates a ThreadFix WAF and returns its JSON.").create("cw"); options.addOption(createWaf); Option searchTeam = OptionBuilder.withArgName("property> <value").hasArgs(2).withLongOpt("search-team") .withDescription("Searches for a ThreadFix team and returns its JSON.").create("st"); options.addOption(searchTeam); Option searchWaf = OptionBuilder.withArgName("property> <value").hasArgs(2).withLongOpt("search-waf") .withDescription("Searches for a ThreadFix WAF and returns its JSON.").create("sw"); options.addOption(searchWaf); Option searchApp = OptionBuilder.withArgName("property> <value1> <value2").hasArgs(3) .withLongOpt("search-app") .withDescription("Searches for a ThreadFix application and returns its JSON.").create("sa"); options.addOption(searchApp); Option upload = OptionBuilder.withArgName("appId> <file").hasArgs(2).withLongOpt("upload") .withDescription("Uploads a scan to the specified application.").create("u"); options.addOption(upload); Option getRules = OptionBuilder.withArgName("wafId").hasArg().withLongOpt("rules") .withDescription("Gets WAF Rules and returns its JSON.").create("r"); options.addOption(getRules); Option getRulesForApp = OptionBuilder.withArgName("wafId> <applicationId").hasArgs(2) .withLongOpt("rules-for-application") .withDescription("Gets WAF Rules for an application and returns its JSON.").create("ra"); options.addOption(getRulesForApp); Option createTag = OptionBuilder.withArgName("name> <[tagType]").hasArgs(2).withLongOpt("create-tag") .withDescription( "Creates a ThreadFix Tag and returns its JSON. tagType is optional, default is Application Tag.") .create("ctg"); options.addOption(createTag); Option searchTag = OptionBuilder.withArgName("property> <value").withValueSeparator(' ').hasArgs(2) .withLongOpt("search-tag") .withDescription("Searches for ThreadFix Tags by either name or id, and returns their JSON.") .create("stg"); options.addOption(searchTag); Option updateTag = OptionBuilder.withArgName("tagId> <name").hasArgs(2).withLongOpt("update-tag") .withDescription("Update ThreadFix Tag, and returns their JSON.").create("utg"); options.addOption(updateTag); Option removeTag = OptionBuilder.withArgName("tagId").hasArgs(1).withLongOpt("remove-tag") .withDescription("Remove ThreadFix Tag, and returns message.").create("rtg"); options.addOption(removeTag); Option tags = OptionBuilder.withLongOpt("tags").withDescription("Fetches a list of ThreadFix tags.") .create("tg"); options.addOption(tags); Option addAppTag = OptionBuilder.withArgName("applicationId> <tagId").withValueSeparator(' ').hasArgs(2) .withLongOpt("addAppTag").withDescription("Add Tag for the given applicationId").create("aat"); options.addOption(addAppTag); Option removeAppTag = OptionBuilder.withArgName("applicationId> <tagId").withValueSeparator(' ').hasArgs(2) .withLongOpt("removeAppTag").withDescription("Remove Tag for the given applicationId") .create("rat"); options.addOption(removeAppTag); Option addComment = OptionBuilder.withArgName("vulnId> <comment> <[commentTagIds]").hasArgs(3) .withLongOpt("add-comment") .withDescription("Add comment to a vulnerability. CommentTagIds is optional, separated by comma.") .create("ac"); options.addOption(addComment); Option submitDefect = OptionBuilder.withArgName("applicationId> <[vulnerabilityIds]> <[*]").hasArgs(1) .hasOptionalArgs().withLongOpt("submit-defect") .withDescription("Submit a defect to the defect tracker configured for a specific application.") .create("sd"); options.addOption(submitDefect); Option getDefectParameters = OptionBuilder.withArgName("applicationId>").hasArgs(1) .withLongOpt("get-defect-parameters") .withDescription("Get a list of parameters from the defect tracker given an application ID.") .create("gdp"); options.addOption(getDefectParameters); return options; }
From source file:br.usp.poli.lta.cereda.spa2run.Utils.java
public static Options getOptions() { Options options = new Options(); Option instrumentation = new Option("i", "instrumentation"); instrumentation.setArgs(Option.UNLIMITED_VALUES); instrumentation.setDescription("instrumentation files"); options.addOption(instrumentation);/*w w w. j a v a 2 s .c om*/ return options; }
From source file:edu.cmu.sv.modelinference.tracestool.Log2Traces.java
public static Options createCmdOptions() { Options options = new Options(); Option help = new Option(HELP_ARG, "print this message"); Option output = Option.builder(OUTPUT_ARG).argName("file").hasArg().desc("Specify output file.").required() .build();/*w w w.java 2 s . c o m*/ options.addOption(help); options.addOption(output); return options; }
From source file:cz.muni.fi.pa165.creatures.rest.client.utils.OptionsProvider.java
public Options getOptions() { if (options != null) { return OptionsProvider.options; }//from w w w . j av a 2 s . c o m OptionsProvider.options = new Options(); Option help = new Option("h", "prints this help"); Option uri = OptionBuilder.withArgName("uri").hasArg().withDescription("uri of the resource we query") .create("u"); Option operation = OptionBuilder.withArgName("operation").hasArg() .withDescription("operation, C, R, U, D, A or N").create("o"); Option idOfEntity = OptionBuilder.withArgName("id").hasArg().withDescription("id of an entity to deal with") .create("i"); Option name = OptionBuilder.withArgName("name").hasArg() .withDescription("name of an entity of a choosen mode").create("n"); // WEAPON Option weapon = OptionBuilder.withDescription("weapon mode").create("w"); Option ammunition = OptionBuilder.withArgName("ammunition").hasArg() .withDescription("ammunition of a weapon in bullets").create("m"); Option range = OptionBuilder.withArgName("range").hasArg().withDescription("range of a weapon in meters") .create("g"); // REGION Option region = OptionBuilder.withDescription("region mode").create("r"); Option description = OptionBuilder.withArgName("description").hasArg() .withDescription("description of a region").create("d"); Option area = OptionBuilder.withArgName("area").hasArg() .withDescription("area of region in square kilometers").create("a"); options.addOption(help); options.addOption(uri); options.addOption(weapon); options.addOption(region); options.addOption(operation); options.addOption(idOfEntity); options.addOption(name); options.addOption(ammunition); options.addOption(range); options.addOption(description); options.addOption(area); return OptionsProvider.options; }
From source file:com.muni.fi.pa165.survive.rest.client.utils.OptionsProvider.java
public Options getOptions() { if (options != null) { return OptionsProvider.options; }//from ww w. j a v a 2 s . co m options = new Options(); Option help = new Option("h", "Print help"); Option operation = OptionBuilder.withArgName("operation").hasArg() .withDescription("operation, C, R, U, D, A").create("o"); Option id = OptionBuilder.withArgName("id").hasArg().withDescription("Entity ID").create("i"); Option name = OptionBuilder.withArgName("name").hasArg() .withDescription("name of an entity of a choosen mode").create("n"); // WEAPON Option weapon = OptionBuilder.withDescription("Weapon Management").create("w"); Option caliber = OptionBuilder.withArgName("caliber").hasArg().withDescription("Weapon ammo caliber (mm)") .create("m"); Option range = OptionBuilder.withArgName("range").hasArg().withDescription("Weapon range in meters") .create("g"); Option rounds = OptionBuilder.withArgName("rounds").hasArg() .withDescription("Number of rounds a weapon holds").create("r"); Option weaponType = OptionBuilder.withArgName("Weapon Type").hasArg() .withDescription("Weapon Type: " + WeaponType.getList()).create("t"); Option weaponClass = OptionBuilder.withArgName("Weapon Class").hasArg() .withDescription("Weapon Class: " + WeaponClass.getList()).create("c"); //AREA Option area = OptionBuilder.withDescription("Area Management").create("a"); Option description = OptionBuilder.withArgName("Description").hasArg().withDescription("Area description") .create("d"); Option terrain = OptionBuilder.withArgName("Area Terrain").hasArg() .withDescription("Terrain Type: " + TerrainType.getList()).create("q"); options.addOption(help); options.addOption(weaponType); options.addOption(weaponClass); options.addOption(rounds); options.addOption(weapon); options.addOption(area); options.addOption(operation); options.addOption(id); options.addOption(name); options.addOption(caliber); options.addOption(range); options.addOption(description); options.addOption(terrain); return options; }
From source file:de.thischwa.pmcms.tool.CliParser.java
private void buildOptions() { Option help = new Option("help", "print this message"); Option admin = new Option("admin", "start poormans in the admin mode"); Option cleanUp = new Option("cleanup", "clean up the settings and site data, all data will be deleted !!!"); Option dataDir = new Option("datadir", true, "full path of the data directory (will ignored if 'portable' is set)"); dataDir.setArgName("path"); Option debug = new Option("debug", "print out debug statements on stdout while starting"); Option portable = new Option("portable", "for running on a portable device"); options = new Options(); options.addOption(help);// w w w.j a v a2s .co m options.addOption(admin); options.addOption(cleanUp); options.addOption(dataDir); options.addOption(debug); options.addOption(portable); }
From source file:com.octo.mbo.CopyNotes.java
static CommandLine parseCommandLine(String[] args) throws CommandLineException { Options options = new Options(); Option optSource = new Option("s", "Source file where the comments can be extracted (only pptx format supported)"); optSource.setRequired(true);/*from w w w.java 2s. c om*/ optSource.setArgs(1); optSource.setLongOpt("source"); options.addOption(optSource); Option optTarget = new Option("t", "Target file where the comments are merged (case of pptx format)"); optTarget.setRequired(true); optTarget.setArgs(1); optTarget.setLongOpt("target"); options.addOption(optTarget); HelpFormatter formatter = new HelpFormatter(); final String header = "CopyNotes allows to extract, copy and merge notes of pptx files. \n" + "Notes can be merged with the notes of an existing files \n" + "Notes can be exported to a xml file with a custom format or imported \n" + "from this xml format and merged into an existing pptx document. \n" + "The target file is updated \n"; final String footer = ""; CommandLineParser cliParser = new DefaultParser(); try { return cliParser.parse(options, args); } catch (MissingOptionException mex) { log.error(mex.getMessage()); log.debug("Error parsing command line", mex); formatter.printHelp( "java -jar copypptxnotes-<version>-jar-with-dependencies.jar -s <source> -t <target>", header, options, footer); throw new CommandLineException("Missing option", mex); } catch (ParseException pex) { log.debug("Error parsing the command line. Please use CopyComment --help", pex); formatter.printHelp( "java -jar copypptxnotes-<version>-jar-with-dependencies.jar -s <source> -t <target>", header, options, footer); throw new CommandLineException("Parse Exception", pex); } }
From source file:com.emc.ecs.util.OptionBuilder.java
public Option create(String opt) { // create the option Option option = new Option(opt, description); // set the option properties option.setLongOpt(longOpt);/*from w w w . j av a 2 s . c o m*/ option.setArgs(argNum); option.setValueSeparator(valueSep); option.setArgName(argName); return option; }
From source file:edu.umass.cs.gnsclient.console.CommandLineInterface.java
private static CommandLine initializeOptions(String[] args) throws ParseException { Option help = new Option("help", "Prints Usage"); Option silent = new Option("silent", "Disables output"); Option noDefaults = new Option("noDefaults", "Don't use server and guid defaults"); commandLineOptions = new Options(); commandLineOptions.addOption(help);/*from ww w . j a v a 2 s. c o m*/ commandLineOptions.addOption(silent); commandLineOptions.addOption(noDefaults); CommandLineParser parser = new GnuParser(); return parser.parse(commandLineOptions, args, false); }