List of usage examples for org.apache.commons.cli CommandLine hasOption
public boolean hasOption(char opt)
From source file:com.adobe.aem.demo.Analytics.java
public static void main(String[] args) { String hostname = null;//from w w w. ja va 2 s. com String url = null; String eventfile = null; // Command line options for this tool Options options = new Options(); options.addOption("h", true, "Hostname"); options.addOption("u", true, "Url"); options.addOption("f", true, "Event data file"); CommandLineParser parser = new BasicParser(); try { CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("u")) { url = cmd.getOptionValue("u"); } if (cmd.hasOption("f")) { eventfile = cmd.getOptionValue("f"); } if (cmd.hasOption("h")) { hostname = cmd.getOptionValue("h"); } if (eventfile == null || hostname == null || url == null) { System.out.println("Command line parameters: -h hostname -u url -f path_to_XML_file"); System.exit(-1); } } catch (ParseException ex) { logger.error(ex.getMessage()); } URLConnection urlConn = null; DataOutputStream printout = null; BufferedReader input = null; String u = "http://" + hostname + "/" + url; String tmp = null; try { URL myurl = new URL(u); urlConn = myurl.openConnection(); urlConn.setDoInput(true); urlConn.setDoOutput(true); urlConn.setUseCaches(false); urlConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); printout = new DataOutputStream(urlConn.getOutputStream()); String xml = readFile(eventfile, StandardCharsets.UTF_8); printout.writeBytes(xml); printout.flush(); printout.close(); input = new BufferedReader(new InputStreamReader(urlConn.getInputStream())); logger.debug(xml); while (null != ((tmp = input.readLine()))) { logger.debug(tmp); } printout.close(); input.close(); } catch (Exception ex) { logger.error(ex.getMessage()); } }
From source file:de.drippinger.serviceExtractor.CLIEntry.java
public static void main(String... args) { Banner.printBanner();// w w w . jav a 2s . co m try { CommandLineParser parser = new DefaultParser(); CommandLine cmd = parser.parse(createOptions(), args); RunParameter parameter = null; if (cmd.hasOption("h")) { printHelp(); } else if (cmd.hasOption("c")) { parameter = extractParameterFromConfigFile(cmd); } else { parameter = extractParameterFromCommandline(cmd); } if (parameter != null && parameter.hasSufficientData()) { parameter.printParameter(); // TODO Do main stuff } else { log.warn("Not sufficient parameters provided. exiting"); } } catch (ParseException | ExtractorException e) { log.error(e.toString()); } }
From source file:edu.cmu.lti.oaqa.annographix.apps.SolrSimpleIndexApp.java
public static void main(String[] args) { Options options = new Options(); options.addOption("i", null, true, "Input File"); options.addOption("u", null, true, "Solr URI"); options.addOption("n", null, true, "Batch size"); CommandLineParser parser = new org.apache.commons.cli.GnuParser(); try {/*from ww w . j av a 2s .co m*/ CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("i")) { inputFile = cmd.getOptionValue("i"); } else { Usage("Specify Input File"); } if (cmd.hasOption("u")) { solrURI = cmd.getOptionValue("u"); } else { Usage("Specify Solr URI"); } if (cmd.hasOption("n")) { batchQty = Integer.parseInt(cmd.getOptionValue("n")); } SolrServerWrapper solrServer = new SolrServerWrapper(solrURI); BufferedReader inpText = new BufferedReader( new InputStreamReader(CompressUtils.createInputStream(inputFile))); XmlHelper xmlHlp = new XmlHelper(); String docText = XmlHelper.readNextXMLIndexEntry(inpText); for (int docNum = 1; docText != null; ++docNum, docText = XmlHelper.readNextXMLIndexEntry(inpText)) { // 1. Read document text Map<String, String> docFields = null; HashMap<String, Object> objDocFields = new HashMap<String, Object>(); try { docFields = xmlHlp.parseXMLIndexEntry(docText); } catch (SAXException e) { System.err.println("Parsing error, offending DOC:" + NL + docText); throw new Exception("Parsing error."); } for (Map.Entry<String, String> e : docFields.entrySet()) { //System.out.println(e.getKey() + " " + e.getValue()); objDocFields.put(e.getKey(), e.getValue()); } solrServer.indexDocument(objDocFields); if ((docNum - 1) % batchQty == 0) solrServer.indexCommit(); } solrServer.indexCommit(); } catch (ParseException e) { Usage("Cannot parse arguments"); } catch (Exception e) { System.err.println("Terminating due to an exception: " + e); System.exit(1); } }
From source file:me.cavar.pg2tei.Gutenberg2TEI.java
/** * @param args/* w w w.j av a 2 s . co m*/ */ public static void main(String[] args) { // Process command line Options options = new Options(); options.addOption("c", true, "Catalogue URL"); options.addOption("o", true, "Output folder"); // options.addOption("f", true, "Resulting output catalogue file name"); options.addOption("h", false, "Help"); // the individual RDF-files are at this URL: // The RDF-file name is this.idN + ".rdf" String ebookURLStr = "http://www.gutenberg.org/ebooks/"; // the URL to the catalog.rdf String catalogURLStr = "http://www.gutenberg.org/feeds/catalog.rdf.zip"; String outputFolder = "."; String catalogOutFN = "catalog.rdf"; CommandLineParser parser; parser = new PosixParser(); try { CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("h")) { System.out.println("Project Gutenberg fetch RDF catalog, HTML-files and generate TEI XML"); System.out.println(""); return; } if (cmd.hasOption("c")) { catalogURLStr = cmd.getOptionValue("c"); } if (cmd.hasOption("o")) { outputFolder = cmd.getOptionValue("o"); } //if (cmd.hasOption("f")) { // catalogOutFN = cmd.getOptionValue("f"); //} } catch (ParseException ex) { System.out.println("Command line argument error:" + ex.getMessage()); } // Do the fetching of the RDF catalog fetchRDF(catalogURLStr, outputFolder, catalogOutFN); // process the RDF file processRDF(outputFolder, catalogOutFN, ebookURLStr); }
From source file:com.ottogroup.bi.spqr.websocket.server.SPQRWebSocketServer.java
/** * Checks the command-line settings and ramps up the server * @param args arguments passed from command-line * @throws ParseException indicates that parsing the command-line failed for any reason * @throws InterruptedException /* w ww .j av a 2 s. c o m*/ * @throws IOException */ public static void main(String[] args) throws ParseException, IOException, InterruptedException { //////////////////////////////////////////////////////////////////////// // evaluate command-line and ensure that it provides valid input CommandLineParser parser = new PosixParser(); CommandLine commandLine = parser.parse(getOptions(), args); if (commandLine.hasOption(CFG_HELP)) { new HelpFormatter().printHelp("spqr-websocket-server", getOptions()); return; } if (!commandLine.hasOption(CFG_CONFIGURATION_FILE)) { new HelpFormatter().printHelp("spqr-websocket-server", "", getOptions(), "Missing required configuration file"); return; } // //////////////////////////////////////////////////////////////////////// new SPQRWebSocketServer().run(commandLine.getOptionValue(CFG_CONFIGURATION_FILE)); }
From source file:com.teradata.tempto.sql.SqlResultGenerator.java
/** * The easiest way to generate expected results is to use * the python front-end (generate_results.py). * * @param args/*from w ww .j a v a 2 s .c o m*/ */ public static void main(String[] args) { Options options = configureCommandLineParser(); try { CommandLineParser parser = new BasicParser(); CommandLine commandLine = parser.parse(options, args); if (commandLine.hasOption(HELP)) { usage(options); return; } String propertiesFileName = commandLine.getOptionValue("p"); String testFileName = commandLine.getOptionValue("s"); SqlResultGenerator resultGenerator = new SqlResultGenerator(testFileName, propertiesFileName); resultGenerator.generateExpectedResults(); } catch (ParseException e) { usage(options); } catch (Exception e) { LOGGER.error("Caught exception in main", e); } System.exit(99); }
From source file:eu.scape_project.arc2warc.Arc2WarcMigration.java
/** * Main entry point./*from w w w. j a v a 2 s . com*/ * * @param args * @throws java.io.IOException * @throws org.apache.commons.cli.ParseException */ public static void main(String[] args) throws IOException, ParseException { Configuration conf = new Configuration(); // Command line interface config = new Arc2WarcMigrationConfig(); CommandLineParser cmdParser = new PosixParser(); GenericOptionsParser gop = new GenericOptionsParser(conf, args); Arc2WarcMigrationOptions a2wopt = new Arc2WarcMigrationOptions(); CommandLine cmd = cmdParser.parse(a2wopt.options, gop.getRemainingArgs()); if ((args.length == 0) || (cmd.hasOption(a2wopt.HELP_OPT))) { a2wopt.exit("Help", 0); } else { a2wopt.initOptions(cmd, config); } Arc2WarcMigration a2wm = new Arc2WarcMigration(); long startMillis = System.currentTimeMillis(); File input = new File(config.getInputStr()); if (input.isDirectory()) { config.setDirectoryInput(true); a2wm.traverseDir(input); } else { migrate(input); } long elapsedTimeMillis = System.currentTimeMillis() - startMillis; LOG.info("Processing time (sec): " + elapsedTimeMillis / 1000F); System.exit(0); }
From source file:gr.kzps.FileCrypto.executor.Executor.java
public static void main(String[] args) { CommandParser commandParser = new CommandParser(args); String inputDir, outputDir, cryptoKey = null; try {/*from w ww . j a va2 s . co m*/ CommandLine cmd = commandParser.parseArgs(); if (cmd.hasOption(ArgumentsName.HELP_L)) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("FileCrypto", commandParser.getOptions()); } else if (cmd.hasOption(ArgumentsName.DECRYPT_L)) { log.info("Decrypt operation"); inputDir = getCryptoDir(cmd, ArgumentsName.INPUTDIR_L); outputDir = getCryptoDir(cmd, ArgumentsName.OUTPUTDIR_L); try { cryptoKey = getCryptoKey(cmd); } catch (NoCryptoKeyProvided ex) { System.err.println(ex.getMessage()); } Integer threshold = getThreshold(cmd); callDispatcher(CryptoOperation.DECRYPT, inputDir, outputDir, threshold, cryptoKey); } else if (cmd.hasOption(ArgumentsName.ENCRYPT_L)) { log.info("Encrypt operation"); inputDir = getCryptoDir(cmd, ArgumentsName.INPUTDIR_L); outputDir = getCryptoDir(cmd, ArgumentsName.OUTPUTDIR_L); try { cryptoKey = getCryptoKey(cmd); } catch (NoCryptoKeyProvided ex) { System.err.println(ex.getMessage()); } Integer threshold = getThreshold(cmd); callDispatcher(CryptoOperation.ENCRYPT, inputDir, outputDir, threshold, cryptoKey); } else if (cmd.hasOption(ArgumentsName.VERSION_L)) { System.out.println("Version: " + VERSION); } } catch (ParseException ex) { log.error("Could not parse arguments! Reason: {}", new Object[] { ex.getStackTrace() }); } }
From source file:com.baystep.jukeberry.JukeBerry.java
/** * @param args the command line arguments *///from w w w . j ava 2s . co m public static void main(String[] args) { System.out.println("Berry Music\n"); JukeBerry bm = new JukeBerry(); buildOptions(); CommandLineParser cmdParser = new DefaultParser(); try { CommandLine cmd = cmdParser.parse(cmdOptions, args); if (cmd.hasOption("h")) { cmdHelp.printHelp("BerryMusic", help_Header, cmdOptions, help_Footer, true); System.exit(0); } if (cmd.hasOption("pw")) bm.config.httpPort = Integer.parseInt(cmd.getOptionValue("pw")); if (cmd.hasOption("ps")) bm.config.websocketPort = Integer.parseInt(cmd.getOptionValue("ps")); if (cmd.hasOption("d")) { String dOpt = cmd.getOptionValue("d"); bm.config.setDisableOption(dOpt); } if (cmd.hasOption("ss")) bm.config.mpStartService = cmd.getOptionValue("ss"); if (cmd.hasOption("sc")) { BerryLogger.supressConsole(); } } catch (ParseException pe) { System.err.println("Command line parsing failed, reason: " + pe.getMessage()); } bm.init(); }
From source file:edu.msu.cme.rdp.classifier.train.validation.crossvalidate.CrossValidateMain.java
/** * This is the main method for cross validation test. * @param args/*from ww w. j a v a2 s.co m*/ * @throws IOException */ public static void main(String[] args) throws IOException { String tax_file = null; String source_file = null; String out_file = null; Integer partialLength = null; // default is full length float fraction = 0.1f; String rdmSelectedRank = null; int min_bootstrap_words = NBClassifier.MIN_BOOTSTRSP_WORDS; try { CommandLine line = new PosixParser().parse(options, args); if (line.hasOption(TRAIN_TAXONFILE_SHORT_OPT)) { tax_file = line.getOptionValue(TRAIN_TAXONFILE_SHORT_OPT); } else { throw new ParseException("Taxonomy file must be specified"); } if (line.hasOption(TRAIN_SEQFILE_SHORT_OPT)) { source_file = line.getOptionValue(TRAIN_SEQFILE_SHORT_OPT); } else { throw new ParseException("Source training fasta file must be specified"); } if (line.hasOption(OUTFILE_SHORT_OPT)) { out_file = line.getOptionValue(OUTFILE_SHORT_OPT); } else { throw new ParseException("Output file must be specified"); } if (line.hasOption(LENGTH_SHORT_OPT)) { ; partialLength = new Integer(line.getOptionValue(LENGTH_SHORT_OPT)); } if (line.hasOption("fraction")) { fraction = Float.parseFloat(line.getOptionValue("fraction")); } if (line.hasOption("rdmRank")) { rdmSelectedRank = line.getOptionValue("rdmRank"); } if (line.hasOption(CmdOptions.MIN_BOOTSTRAP_WORDS_SHORT_OPT)) { min_bootstrap_words = Integer .parseInt(line.getOptionValue(CmdOptions.MIN_BOOTSTRAP_WORDS_SHORT_OPT)); if (min_bootstrap_words < NBClassifier.MIN_BOOTSTRSP_WORDS) { throw new IllegalArgumentException( min_bootstrap_words + " must be at least " + NBClassifier.MIN_BOOTSTRSP_WORDS); } } } catch (ParseException ex) { new HelpFormatter().printHelp(120, "CrossValidateMain", "", options, "", true); return; } boolean useSeed = true; // use seed for random number generator CrossValidate theObj = new CrossValidate(); theObj.runTest(new File(tax_file), new File(source_file), new File(out_file), rdmSelectedRank, fraction, partialLength, useSeed, min_bootstrap_words); }