List of usage examples for org.apache.commons.cli Options addOption
public Options addOption(Option opt)
From source file:eu.annocultor.utils.XmlUtils.java
public static void main(String... args) throws Exception { // Handling command line parameters with Apache Commons CLI Options options = new Options(); options.addOption(OptionBuilder.withArgName(OPT_FN).hasArg().isRequired() .withDescription("XML file name to be pretty-printed").create(OPT_FN)); // now lets parse the input CommandLineParser parser = new BasicParser(); CommandLine cmd;/*from w w w .j av a 2 s. c o m*/ try { cmd = parser.parse(options, Utils.getCommandLineFromANNOCULTOR_ARGS(args)); } catch (ParseException pe) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("pretty", options); return; } List<File> files = Utils.expandFileTemplateFrom(new File("."), cmd.getOptionValue(OPT_FN)); for (File file : files) { // XML pretty print System.out.println("Pretty-print for file " + file); if (file.exists()) prettyPrintXmlFileSAX(file.getCanonicalPath()); else throw new Exception("File not found: " + file.getCanonicalPath()); } }
From source file:com.esri.geoevent.test.performance.OrchestratorMain.java
/** * Main method - this is used to when running from command line * * @param args Command Line Arguments//from w ww . ja va 2 s . co m */ @SuppressWarnings("static-access") public static void main(String[] args) { // TODO: Localize the messages // test harness options Options testHarnessOptions = new Options(); testHarnessOptions.addOption(OptionBuilder.withLongOpt("fixtures") .withDescription("The fixtures xml file to load and configure the performance test harness.") .hasArg().create("f")); testHarnessOptions.addOption("h", "help", false, "print the help message"); // parse the command line CommandLineParser parser = new BasicParser(); CommandLine cmd = null; try { cmd = parser.parse(testHarnessOptions, args, false); } catch (ParseException ignore) { printHelp(testHarnessOptions); return; } if (cmd.getOptions().length == 0) { OrchestratorUI ui = new OrchestratorUI(); ui.run(args); } else { if (cmd.hasOption("h")) { printHelp(testHarnessOptions); return; } if (cmd.hasOption("h") || !cmd.hasOption("f")) { printHelp(testHarnessOptions); return; } String fixturesFilePath = cmd.getOptionValue("f"); // validate if (!validateFixturesFile(fixturesFilePath)) { printHelp(testHarnessOptions); return; } // parse the xml file final Fixtures fixtures; try { fixtures = fromXML(fixturesFilePath); } catch (JAXBException error) { System.err.println(ImplMessages.getMessage("TEST_HARNESS_EXECUTOR_CONFIG_ERROR", fixturesFilePath)); error.printStackTrace(); return; } // run the test harness try { OrchestratorRunner executor = new OrchestratorRunner(fixtures); executor.start(); } catch (RunningException error) { error.printStackTrace(); } } }
From source file:dyco4j.instrumentation.internals.CLI.java
public static void main(final String[] args) throws IOException { final Options _options = new Options(); _options.addOption(Option.builder().longOpt(IN_FOLDER_OPTION).required().hasArg(true) .desc("Folders containing the classes to be instrumented.").build()); _options.addOption(Option.builder().longOpt(OUT_FOLDER_OPTION).required().hasArg(true) .desc("Folder containing the classes (as descendants) with instrumentation.").build()); _options.addOption(Option.builder().longOpt(CLASSPATH_CONFIG_OPTION).hasArg(true) .desc("File containing class path (1 entry per line) used by classes to be instrumented.").build()); final String _msg = MessageFormat.format("Regex identifying the methods to be instrumented. Default: {0}.", METHOD_NAME_REGEX);// ww w .j av a 2s . c o m _options.addOption(Option.builder().longOpt(METHOD_NAME_REGEX_OPTION).hasArg(true).desc(_msg).build()); _options.addOption(Option.builder().longOpt(TRACE_ARRAY_ACCESS_OPTION).hasArg(false) .desc("Instrument to trace array access.").build()); _options.addOption(Option.builder().longOpt(TRACE_FIELD_ACCESS_OPTION).hasArg(false) .desc("Instrument to trace field access.").build()); _options.addOption(Option.builder().longOpt(TRACE_METHOD_ARGUMENTS_OPTION).hasArg(false) .desc("Instrument to trace method arguments.").build()); _options.addOption(Option.builder().longOpt(TRACE_METHOD_CALL_OPTION).hasArg(false) .desc("Instrument to trace method calls (compile-time signatures).").build()); _options.addOption(Option.builder().longOpt(TRACE_METHOD_RETURN_VALUE_OPTION).hasArg(false) .desc("Instrument to trace method return values.").build()); try { final CommandLine _cmdLine = new DefaultParser().parse(_options, args); extendClassPath(_cmdLine); processCommandLine(_cmdLine); } catch (final ParseException _ex1) { new HelpFormatter().printHelp(CLI.class.getName(), _options); } }
From source file:mx.unam.fesa.isoo.msp.MSPMain.java
/** * @param args//w ww . j a v a 2 s. c om * @throws Exception */ @SuppressWarnings("static-access") public static void main(String[] args) { // // creating options // Options options = new Options(); // help option // options.addOption( OptionBuilder.withDescription("Prints this message.").withLongOpt("help").create(OPT_HELP)); // server option // options.addOption(OptionBuilder.withDescription("The server this MineSweeperPlayer will connect to.") .hasArg().withArgName("SERVER").withLongOpt("server").create(OPT_SERVER)); // port option // options.addOption(OptionBuilder.withDescription("The port this MineSweeperPlayer will connect to.").hasArg() .withType(new Integer(0)).withArgName("PORT").withLongOpt("port").create(OPT_PORT)); // parsing options // String hostname = DEFAULT_SERVER; int port = DEFAULT_PORT; try { // using GNU standard // CommandLine line = new GnuParser().parse(options, args); if (line.hasOption(OPT_HELP)) { new HelpFormatter().printHelp("msc [options]", options); return; } if (line.hasOption(OPT_PORT)) { try { port = (Integer) line.getOptionObject(OPT_PORT); } catch (Exception e) { } } if (line.hasOption(OPT_SERVER)) { hostname = line.getOptionValue(OPT_PORT); } } catch (ParseException e) { System.err.println("Could not parse command line options correctly: " + e.getMessage()); return; } // // configuring logging services // try { LogManager.getLogManager() .readConfiguration(ClassLoader.getSystemResourceAsStream(DEFAULT_LOGGING_CONFIG_FILE)); } catch (Exception e) { throw new Error("Could not load logging properties file.", e); } // // setting up Mine Sweeper client // try { new MSClient(hostname, port); } catch (Exception e) { System.err.println("Could not execute MineSweeper client: " + e.getMessage()); } }
From source file:com.act.utils.parser.UniprotInterpreter.java
public static void main(String[] args) throws ParserConfigurationException, IOException, SAXException, CompoundNotFoundException { Options opts = new Options(); for (Option.Builder b : OPTION_BUILDERS) { opts.addOption(b.build()); }/*from w ww .j a va2 s . c o m*/ CommandLine cl = null; try { CommandLineParser parser = new DefaultParser(); cl = parser.parse(opts, args); } catch (ParseException e) { LOGGER.error("Argument parsing failed: %s", e.getMessage()); HELP_FORMATTER.printHelp(UniprotInterpreter.class.getCanonicalName(), HELP_MESSAGE, opts, null, true); System.exit(1); } if (cl.hasOption("help")) { HELP_FORMATTER.printHelp(UniprotInterpreter.class.getCanonicalName(), HELP_MESSAGE, opts, null, true); System.exit(1); } File uniprotFile = new File(cl.getOptionValue(OPTION_UNIPROT_PATH)); if (!uniprotFile.exists()) { String msg = "Uniprot file path is null"; LOGGER.error(msg); throw new RuntimeException(msg); } else { UniprotInterpreter reader = new UniprotInterpreter(uniprotFile); reader.init(); } }
From source file:com.gordcorp.jira2db.App.java
public static void main(String[] args) throws Exception { File log4jFile = new File("log4j.xml"); if (log4jFile.exists()) { DOMConfigurator.configure("log4j.xml"); }/* w ww . ja va 2 s.c o m*/ Option help = new Option("h", "help", false, "print this message"); @SuppressWarnings("static-access") Option project = OptionBuilder.withLongOpt("project").withDescription("Only sync Jira project PROJECT") .hasArg().withArgName("PROJECT").create(); @SuppressWarnings("static-access") Option property = OptionBuilder.withArgName("property=value").hasArgs(2).withValueSeparator() .withDescription("use value for given property").create("D"); @SuppressWarnings("static-access") Option testJira = OptionBuilder.withLongOpt("test-jira") .withDescription("Test the connection to Jira and print the results").create(); @SuppressWarnings("static-access") Option forever = OptionBuilder.withLongOpt("forever") .withDescription("Will continue polling Jira and syncing forever").create(); Options options = new Options(); options.addOption(help); options.addOption(project); options.addOption(property); options.addOption(testJira); options.addOption(forever); CommandLineParser parser = new GnuParser(); try { CommandLine line = parser.parse(options, args); if (line.hasOption(help.getOpt())) { printHelp(options); return; } // Overwrite the properties file with command line arguments if (line.hasOption("D")) { String[] values = line.getOptionValues("D"); for (int i = 0; i < values.length; i = i + 2) { String key = values[i]; // If user does not provide a value for this property, use // an empty string String value = ""; if (i + 1 < values.length) { value = values[i + 1]; } log.info("Setting key=" + key + " value=" + value); PropertiesWrapper.set(key, value); } } if (line.hasOption("test-jira")) { testJira(); } else { JiraSynchroniser jira = new JiraSynchroniser(); if (line.hasOption("project")) { jira.setProjects(Arrays.asList(new String[] { line.getOptionValue("project") })); } if (line.hasOption("forever")) { jira.syncForever(); } else { jira.syncAll(); } } } catch (ParseException exp) { log.error("Parsing failed: " + exp.getMessage()); } catch (Exception e) { log.error(e.getMessage(), e); } }
From source file:de.unirostock.sems.caro.CaRo.java
/** * The main method to be called by the command line. * /*from w w w. ja v a 2s. c o m*/ * @param args * the arguments */ public static void main(String[] args) { Options options = new Options(); options.addOption(new Option("h", "help", false, "print the help message")); options.addOption( Option.builder().longOpt("roca").desc("convert a research object into a combine archive").build()); options.addOption( Option.builder().longOpt("caro").desc("convert a combine archive into a research object").build()); options.addOption(Option.builder("i").longOpt("in").required().argName("FILE").hasArg() .desc("source container to be converted").build()); options.addOption(Option.builder("o").longOpt("out").required().argName("FILE").hasArg() .desc("target container to be created").build()); CommandLineParser parser = new DefaultParser(); CommandLine line = null; try { line = parser.parse(options, args); if (line.hasOption("help")) { help(options, null); return; } } catch (ParseException e) { help(options, "Parsing of command line options failed. Reason: " + e.getMessage()); return; } File in = new File(line.getOptionValue("in")); File out = new File(line.getOptionValue("out")); if (!in.exists()) { help(options, "file " + in + " does not exist"); return; } if (out.exists()) { help(options, "file " + out + " already exist"); return; } if (line.hasOption("caro") && line.hasOption("roca")) { help(options, "only one of --roca and --caro is allowed"); return; } CaRoConverter conv = null; if (line.hasOption("caro")) conv = new CaToRo(in); else if (line.hasOption("roca")) conv = new RoToCa(in); else { help(options, "you need to either supply --roca or --caro"); return; } conv.convertTo(out); if (conv.hasErrors()) System.err.println("There were errors!"); if (conv.hasWarnings()) System.err.println("There were warnings!"); List<CaRoNotification> notifications = conv.getNotifications(); for (CaRoNotification note : notifications) System.out.println(note); }
From source file:net.geoprism.FileMerger.java
public static void main(String[] args) throws ParseException, IOException { CommandLineParser parser = new DefaultParser(); Options options = new Options(); options.addOption(Option.builder("b").hasArg().argName("baseFile").longOpt("baseFile") .desc("The path to the base properties file.").build()); options.addOption(Option.builder("o").hasArg().argName("overrideFile").longOpt("overrideFile") .desc("The path to the override properties file.").build()); options.addOption(Option.builder("e").hasArg().argName("exportFile").longOpt("exportFile") .desc("The path to the export properties file. A null value defaults to base.").build()); options.addOption(Option.builder("B").hasArg().argName("baseDir").longOpt("baseDir") .desc("The path to the base directory.").build()); options.addOption(Option.builder("O").hasArg().argName("overrideDir").longOpt("overrideDir") .desc("The path to the override directory.").build()); options.addOption(Option.builder("E").hasArg().argName("exportDir").longOpt("exportDir") .desc("The path to the export directory. A null value defaults to base.").build()); CommandLine line = parser.parse(options, args); String sBase = line.getOptionValue("b"); String sOverride = line.getOptionValue("o"); String sExport = line.getOptionValue("e"); String sBaseDir = line.getOptionValue("B"); String sOverrideDir = line.getOptionValue("O"); String sExportDir = line.getOptionValue("E"); if (sBase != null && sOverride != null) { if (sExport == null) { sExport = sBase;// w ww.j a v a 2 s . c o m } File fBase = new File(sBase); File fOverride = new File(sOverride); File fExport = new File(sExport); if (!fBase.exists() || !fOverride.exists()) { throw new RuntimeException( "The base [" + sBase + "] and the override [" + sOverride + "] paths must both exist."); } FileMerger merger = new FileMerger(); merger.mergeProperties(fBase, fOverride, fExport); } else if (sBaseDir != null && sOverrideDir != null) { if (sExportDir == null) { sExportDir = sBaseDir; } File fBaseDir = new File(sBaseDir); File fOverrideDir = new File(sOverrideDir); File fExportDir = new File(sExportDir); if (!fBaseDir.exists() || !fOverrideDir.exists()) { throw new RuntimeException("The base [" + sBaseDir + "] and the override [" + sOverrideDir + "] paths must both exist."); } FileMerger merger = new FileMerger(); merger.mergeDirectories(fBaseDir, fOverrideDir, fExportDir); } else { throw new RuntimeException("Invalid arguments"); } }
From source file:com.browseengine.bobo.index.MakeBobo.java
/** * @param args//from w w w .jav a 2 s . c om */ public static void main(String[] args) throws IOException { // TODO Auto-generated method stub Option help = new Option("help", false, "print this message"); OptionBuilder.withArgName("path"); OptionBuilder.hasArg(); OptionBuilder.withDescription("data source - required"); Option src = OptionBuilder.create("source"); src.setRequired(true); OptionBuilder.withArgName("path"); OptionBuilder.hasArg(); OptionBuilder.withDescription("index to create - required"); Option index = OptionBuilder.create("index"); index.setRequired(true); OptionBuilder.withArgName("file"); OptionBuilder.hasArg(); OptionBuilder.withDescription("field configuration - optional"); Option conf = OptionBuilder.create("conf"); OptionBuilder.withArgName("class"); OptionBuilder.hasArg(); OptionBuilder.withDescription("class name of the data digester - default: xml digester"); Option digesterOpt = OptionBuilder.create("digester"); OptionBuilder.withArgName("name"); OptionBuilder.hasArg(); OptionBuilder.withDescription("character set name - default: UTF-8"); Option charset = OptionBuilder.create("charset"); OptionBuilder.withArgName("maxdocs"); OptionBuilder.hasArg(); OptionBuilder.withDescription("maximum number of documents - default: 100"); Option maxdocs = OptionBuilder.create("maxdocs"); Options options = new Options(); options.addOption(help); options.addOption(conf); options.addOption(index); options.addOption(src); options.addOption(charset); options.addOption(digesterOpt); options.addOption(maxdocs); // create the parser CommandLineParser parser = new BasicParser(); try { // parse the command line arguments CommandLine line = parser.parse(options, args); String output = line.getOptionValue("index"); File data = new File(line.getOptionValue("source")); Class digesterClass; if (line.hasOption("digester")) digesterClass = Class.forName(line.getOptionValue("digester")); else throw new RuntimeException("digester not specified"); Charset chset; if (line.hasOption("charset")) { chset = Charset.forName(line.getOptionValue("charset")); } else { chset = Charset.forName("UTF-8"); } int maxDocs; try { maxDocs = Integer.parseInt(line.getOptionValue("maxdocs")); } catch (Exception e) { maxDocs = 100; } FileDigester digester; try { Constructor constructor = digesterClass.getConstructor(new Class[] { File.class }); digester = (FileDigester) constructor.newInstance(new Object[] { data }); digester.setCharset(chset); digester.setMaxDocs(maxDocs); } catch (Exception e) { throw new RuntimeException("Invalid digester class.", e); } BoboIndexer indexer = new BoboIndexer(digester, FSDirectory.open(new File(output))); indexer.index(); } catch (ParseException exp) { exp.printStackTrace(); usage(options); } catch (ClassNotFoundException e) { System.out.println("Invalid digester class."); usage(options); } }
From source file:SequentialPersonalizedPageRank.java
@SuppressWarnings({ "static-access" }) public static void main(String[] args) throws IOException { Options options = new Options(); options.addOption(OptionBuilder.withArgName("path").hasArg().withDescription("input path").create(INPUT)); options.addOption(/*from ww w . j ava 2s . co m*/ OptionBuilder.withArgName("val").hasArg().withDescription("random jump factor").create(JUMP)); options.addOption(OptionBuilder.withArgName("node").hasArg() .withDescription("source node (i.e., destination of the random jump)").create(SOURCE)); CommandLine cmdline = null; CommandLineParser parser = new GnuParser(); try { cmdline = parser.parse(options, args); } catch (ParseException exp) { System.err.println("Error parsing command line: " + exp.getMessage()); System.exit(-1); } if (!cmdline.hasOption(INPUT) || !cmdline.hasOption(SOURCE)) { System.out.println("args: " + Arrays.toString(args)); HelpFormatter formatter = new HelpFormatter(); formatter.setWidth(120); formatter.printHelp(SequentialPersonalizedPageRank.class.getName(), options); ToolRunner.printGenericCommandUsage(System.out); System.exit(-1); } String infile = cmdline.getOptionValue(INPUT); final String source = cmdline.getOptionValue(SOURCE); float alpha = cmdline.hasOption(JUMP) ? Float.parseFloat(cmdline.getOptionValue(JUMP)) : 0.15f; int edgeCnt = 0; DirectedSparseGraph<String, Integer> graph = new DirectedSparseGraph<String, Integer>(); BufferedReader data = new BufferedReader(new InputStreamReader(new FileInputStream(infile))); String line; while ((line = data.readLine()) != null) { line.trim(); String[] arr = line.split("\\t"); for (int i = 1; i < arr.length; i++) { graph.addEdge(new Integer(edgeCnt++), arr[0], arr[i]); } } data.close(); if (!graph.containsVertex(source)) { System.err.println("Error: source node not found in the graph!"); System.exit(-1); } WeakComponentClusterer<String, Integer> clusterer = new WeakComponentClusterer<String, Integer>(); Set<Set<String>> components = clusterer.transform(graph); int numComponents = components.size(); System.out.println("Number of components: " + numComponents); System.out.println("Number of edges: " + graph.getEdgeCount()); System.out.println("Number of nodes: " + graph.getVertexCount()); System.out.println("Random jump factor: " + alpha); // Compute personalized PageRank. PageRankWithPriors<String, Integer> ranker = new PageRankWithPriors<String, Integer>(graph, new Transformer<String, Double>() { @Override public Double transform(String vertex) { return vertex.equals(source) ? 1.0 : 0; } }, alpha); ranker.evaluate(); // Use priority queue to sort vertices by PageRank values. PriorityQueue<Ranking<String>> q = new PriorityQueue<Ranking<String>>(); int i = 0; for (String pmid : graph.getVertices()) { q.add(new Ranking<String>(i++, ranker.getVertexScore(pmid), pmid)); } // Print PageRank values. System.out.println("\nPageRank of nodes, in descending order:"); Ranking<String> r = null; while ((r = q.poll()) != null) { System.out.println(r.rankScore + "\t" + r.getRanked()); } }