List of usage examples for org.apache.commons.cli Options addOption
public Options addOption(String opt, String longOpt, boolean hasArg, String description)
From source file:FDLRequestor.java
public static void main(String[] args) throws Exception { String hostId = ""; String partnerId = ""; String userId = ""; CommandLineParser parser = new BasicParser(); Options options = new Options(); options.addOption("h", "host", true, "EBICS Host ID"); options.addOption("p", "partner", true, "Registred Partner ID for you user"); options.addOption("u", "user", true, "User ID to initiate"); // Parse the program arguments CommandLine commandLine = parser.parse(options, args); if (!commandLine.hasOption('h')) { System.out.println("Host-ID is mandatory"); System.exit(0);/*from w w w .j av a 2 s. c o m*/ } else { hostId = commandLine.getOptionValue('h'); System.out.println("host: " + hostId); } if (!commandLine.hasOption('p')) { System.out.println("Partner-ID is mandatory"); System.exit(0); } else { partnerId = commandLine.getOptionValue('p'); System.out.println("partnerId: " + partnerId); } if (!commandLine.hasOption('u')) { System.out.println("User-ID is mandatory"); System.exit(0); } else { userId = commandLine.getOptionValue('u'); System.out.println("userId: " + userId); } FDLRequestor fdlRequestor; PasswordCallback pwdHandler; Product product; String filePath; fdlRequestor = new FDLRequestor(); product = new Product("kopiLeft Dev 1.0", Locale.FRANCE, null); pwdHandler = new UserPasswordHandler(userId, "2012"); // Load alredy created user fdlRequestor.loadUser(hostId, partnerId, userId, pwdHandler); filePath = System.getProperty("user.home") + File.separator + "download.txt"; // Send FDL Requets fdlRequestor.fetchFile(filePath, userId, product, OrderType.FDL, true, null, null); }
From source file:FULRequestor.java
public static void main(String[] args) throws Exception { String hostId = ""; String partnerId = ""; String userId = ""; CommandLineParser parser = new BasicParser(); Options options = new Options(); options.addOption("h", "host", true, "EBICS Host ID"); options.addOption("p", "partner", true, "Registred Partner ID for you user"); options.addOption("u", "user", true, "User ID to initiate"); // Parse the program arguments CommandLine commandLine = parser.parse(options, args); if (!commandLine.hasOption('h')) { System.out.println("Host-ID is mandatory"); System.exit(0);/*from w w w . j av a2s . c o m*/ } else { hostId = commandLine.getOptionValue('h'); System.out.println("host: " + hostId); } if (!commandLine.hasOption('p')) { System.out.println("Partner-ID is mandatory"); System.exit(0); } else { partnerId = commandLine.getOptionValue('p'); System.out.println("partnerId: " + partnerId); } if (!commandLine.hasOption('u')) { System.out.println("User-ID is mandatory"); System.exit(0); } else { userId = commandLine.getOptionValue('u'); System.out.println("userId: " + userId); } FULRequestor hbbRequestor; PasswordCallback pwdHandler; Product product; String filePath; hbbRequestor = new FULRequestor(); product = new Product("kopiLeft Dev 1.0", Locale.FRANCE, null); pwdHandler = new UserPasswordHandler(userId, "2012"); // Load alredy created user hbbRequestor.loadUser(hostId, partnerId, userId, pwdHandler); filePath = System.getProperty("user.home") + File.separator + "test.txt"; // Send FUL Requets hbbRequestor.sendFile(filePath, userId, product); }
From source file:com.aerospike.examples.pk.StorePrimaryKey.java
public static void main(String[] args) throws AerospikeException { try {/* w ww . ja va 2 s. c o m*/ Options options = new Options(); options.addOption("h", "host", true, "Server hostname (default: 172.28.128.6)"); options.addOption("p", "port", true, "Server port (default: 3000)"); options.addOption("n", "namespace", true, "Namespace (default: test)"); options.addOption("s", "set", true, "Set (default: demo)"); options.addOption("u", "usage", false, "Print usage."); CommandLineParser parser = new PosixParser(); CommandLine cl = parser.parse(options, args, false); String host = cl.getOptionValue("h", "172.28.128.6"); String portString = cl.getOptionValue("p", "3000"); int port = Integer.parseInt(portString); String namespace = cl.getOptionValue("n", "test"); String set = cl.getOptionValue("s", "demo"); log.debug("Host: " + host); log.debug("Port: " + port); log.debug("Namespace: " + namespace); log.debug("Set: " + set); @SuppressWarnings("unchecked") List<String> cmds = cl.getArgList(); if (cmds.size() == 0 && cl.hasOption("u")) { logUsage(options); return; } StorePrimaryKey as = new StorePrimaryKey(host, port, namespace, set); as.work(); } catch (Exception e) { log.error("Critical error", e); } }
From source file:com.aerospike.examples.BatchUpdateTTL.java
public static void main(String[] args) throws AerospikeException { try {//from w w w . j a va 2 s . c o m Options options = new Options(); options.addOption("h", "host", true, "Server hostname (default: 127.0.0.1)"); options.addOption("p", "port", true, "Server port (default: 3000)"); options.addOption("n", "namespace", true, "Namespace (default: test)"); options.addOption("s", "set", true, "Set (default: demo)"); options.addOption("u", "usage", false, "Print usage."); CommandLineParser parser = new PosixParser(); CommandLine cl = parser.parse(options, args, false); String host = cl.getOptionValue("h", "127.0.0.1"); String portString = cl.getOptionValue("p", "3000"); int port = Integer.parseInt(portString); String namespace = cl.getOptionValue("n", "test"); String set = cl.getOptionValue("s", "demo"); log.debug("Host: " + host); log.debug("Port: " + port); log.debug("Namespace: " + namespace); log.debug("Set: " + set); @SuppressWarnings("unchecked") List<String> cmds = cl.getArgList(); if (cmds.size() == 0 && cl.hasOption("u")) { logUsage(options); return; } BatchUpdateTTL as = new BatchUpdateTTL(host, port, namespace, set); as.work(); } catch (Exception e) { log.error("Critical error", e); } }
From source file:com.spotify.cassandra.opstools.CountTombstones.java
/** * Counts the number of tombstones, per row, in a given SSTable * * Assumes RandomPartitioner, standard columns and UTF8 encoded row keys * * Does not require a cassandra.yaml file or system tables. * * @param args command lines arguments/*from ww w.j a v a 2s .c o m*/ * * @throws java.io.IOException on failure to open/read/write files or output streams */ public static void main(String[] args) throws IOException, ParseException { String usage = String.format("Usage: %s [-l] <sstable> [<sstable> ...]%n", CountTombstones.class.getName()); final Options options = new Options(); options.addOption("l", "legend", false, "Include column name explanation"); options.addOption("p", "partitioner", true, "The partitioner used by database"); CommandLineParser parser = new BasicParser(); CommandLine cmd = parser.parse(options, args); if (cmd.getArgs().length < 1) { System.err.println("You must supply at least one sstable"); System.err.println(usage); System.exit(1); } // Fake DatabaseDescriptor settings so we don't have to load cassandra.yaml etc Config.setClientMode(true); String partitionerName = String.format("org.apache.cassandra.dht.%s", options.hasOption("p") ? options.getOption("p") : "RandomPartitioner"); try { Class<?> clazz = Class.forName(partitionerName); IPartitioner partitioner = (IPartitioner) clazz.newInstance(); DatabaseDescriptor.setPartitioner(partitioner); } catch (Exception e) { throw new RuntimeException("Can't instantiate partitioner " + partitionerName); } PrintStream out = System.out; for (String arg : cmd.getArgs()) { String ssTableFileName = new File(arg).getAbsolutePath(); Descriptor descriptor = Descriptor.fromFilename(ssTableFileName); run(descriptor, cmd, out); } System.exit(0); }
From source file:edu.cmu.lti.oaqa.annographix.apps.SolrIndexApp.java
public static void main(String[] args) { Options options = new Options(); options.addOption("t", null, true, "Text File"); options.addOption("a", null, true, "Annotation File"); options.addOption("u", null, true, "Solr URI"); options.addOption("n", null, true, "Batch size"); options.addOption(/* w w w . j ava 2 s . c o m*/ OptionBuilder.withLongOpt(TEXT_FIELD_ARG).withDescription("Text field name").hasArg().create()); options.addOption(OptionBuilder.withLongOpt(ANNOT_FIELD_ARG).withDescription("Annotation field name") .hasArg().create()); CommandLineParser parser = new org.apache.commons.cli.GnuParser(); try { CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("t")) { docTextFile = cmd.getOptionValue("t"); } else { Usage("Specify Text File"); } if (cmd.hasOption("a")) { docAnnotFile = cmd.getOptionValue("a"); } else { Usage("Specify Annotation File"); } if (cmd.hasOption("u")) { solrURI = cmd.getOptionValue("u"); } else { Usage("Specify Solr URI"); } if (cmd.hasOption("n")) { batchQty = Integer.parseInt(cmd.getOptionValue("n")); } String textFieldName = UtilConst.DEFAULT_TEXT4ANNOT_FIELD; String annotFieldName = UtilConst.DEFAULT_ANNOT_FIELD; if (cmd.hasOption(TEXT_FIELD_ARG)) { textFieldName = cmd.getOptionValue(TEXT_FIELD_ARG); } if (cmd.hasOption(ANNOT_FIELD_ARG)) { annotFieldName = cmd.getOptionValue(ANNOT_FIELD_ARG); } System.out.println(String.format("Annotated text field: '%s', annotation field: '%s'", textFieldName, annotFieldName)); // Ignoring return value here SolrUtils.parseAndCheckConfig(solrURI, textFieldName, annotFieldName); System.out.println("Config is fine!"); DocumentReader.readDoc(docTextFile, textFieldName, docAnnotFile, batchQty, new SolrDocumentIndexer(solrURI, textFieldName, annotFieldName)); } 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:com.subakva.formicid.Main.java
public static void main(final String[] args) { Options options = new Options(); options.addOption("p", "projecthelp", false, "print project help information"); options.addOption("f", "file", true, "use given buildfile"); options.addOption("h", "help", false, "print this message"); options.addOption("d", "debug", false, "print debugging information"); options.addOption("v", "verbose", false, "be extra verbose"); options.addOption("q", "quiet", false, "be extra quiet"); CommandLine cli;/*from w ww . jav a 2 s .co m*/ try { cli = new GnuParser().parse(options, args); } catch (ParseException e) { System.out.println("Error: " + e.getMessage()); new HelpFormatter().printHelp(CLI_SYNTAX, options); return; } String scriptName = cli.getOptionValue("f", "build.js"); if (cli.hasOption("h")) { new HelpFormatter().printHelp(CLI_SYNTAX, options); return; } else if (cli.hasOption("p")) { runScript(scriptName, "projecthelp", null); } else { runScript(scriptName, "build", cli); } }
From source file:dk.statsbiblioteket.util.qa.PackageScannerDriver.java
/** * @param args The command line arguments. * @throws IOException If command line arguments can't be passed or there * is an error reading class files. *//* w ww.ja va 2s .c o m*/ @SuppressWarnings("deprecation") public static void main(final String[] args) throws IOException { Report report; CommandLine cli = null; String reportType, projectName, baseSrcDir, targetPackage; String[] targets = null; // Build command line options CommandLineParser cliParser = new PosixParser(); Options options = new Options(); options.addOption("h", "help", false, "Print help message and exit"); options.addOption("n", "name", true, "Project name, default 'Unknown'"); options.addOption("o", "output", true, "Type of output, 'plain' or 'html', default is html"); options.addOption("p", "package", true, "Only scan a particular package in input dirs, use dotted " + "package notation to refine selections"); options.addOption("s", "source-dir", true, "Base source dir to use in report, can be a URL. " + "@FILE@ and @MODULE@ will be escaped"); // Parse and validate command line try { cli = cliParser.parse(options, args); targets = cli.getArgs(); if (args.length == 0 || targets.length == 0 || cli.hasOption("help")) { throw new ParseException("Not enough arguments, no input files"); } } catch (ParseException e) { printHelp(options); System.exit(1); } // Extract information from command line reportType = cli.getOptionValue("output") != null ? cli.getOptionValue("output") : "html"; projectName = cli.getOptionValue("name") != null ? cli.getOptionValue("name") : "Unknown"; baseSrcDir = cli.getOptionValue("source-dir") != null ? cli.getOptionValue("source-dir") : System.getProperty("user.dir"); targetPackage = cli.getOptionValue("package") != null ? cli.getOptionValue("package") : ""; targetPackage = targetPackage.replace(".", File.separator); // Set up report type if ("plain".equals(reportType)) { report = new BasicReport(); } else { report = new HTMLReport(projectName, System.out, baseSrcDir); } // Do actual scanning of provided targets for (String target : targets) { PackageScanner scanner; File f = new File(target); if (f.isDirectory()) { scanner = new PackageScanner(report, f, targetPackage); } else { String filename = f.toString(); scanner = new PackageScanner(report, f.getParentFile(), filename.substring(filename.lastIndexOf(File.separator) + 1)); } scanner.scan(); } // Cloce the report before we exit report.end(); }
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 {// w ww . ja v a2 s .c o 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:it.tizianofagni.sparkboost.MPBoostLearnerExe.java
public static void main(String[] args) { Options options = new Options(); options.addOption("b", "binaryProblem", false, "Indicate if the input dataset contains a binary problem and not a multilabel one"); options.addOption("z", "labels0based", false, "Indicate if the labels IDs in the dataset to classifyLibSvmWithResults are already assigned in the range [0, numLabels-1] included"); options.addOption("l", "enableSparkLogging", false, "Enable logging messages of Spark"); options.addOption("w", "windowsLocalModeFix", true, "Set the directory containing the winutils.exe command"); options.addOption("dp", "documentPartitions", true, "The number of document partitions"); options.addOption("fp", "featurePartitions", true, "The number of feature partitions"); options.addOption("lp", "labelPartitions", true, "The number of label partitions"); CommandLineParser parser = new BasicParser(); CommandLine cmd = null;/*from w ww. j a v a 2 s .c o m*/ String[] remainingArgs = null; try { cmd = parser.parse(options, args); remainingArgs = cmd.getArgs(); if (remainingArgs.length != 3) throw new ParseException("You need to specify all mandatory parameters"); } catch (ParseException e) { System.out.println("Parsing failed. Reason: " + e.getMessage()); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp( MPBoostLearnerExe.class.getSimpleName() + " [OPTIONS] <inputFile> <outputFile> <numIterations>", options); System.exit(-1); } boolean binaryProblem = false; if (cmd.hasOption("b")) binaryProblem = true; boolean labels0Based = false; if (cmd.hasOption("z")) labels0Based = true; boolean enablingSparkLogging = false; if (cmd.hasOption("l")) enablingSparkLogging = true; if (cmd.hasOption("w")) { System.setProperty("hadoop.home.dir", cmd.getOptionValue("w")); } String inputFile = remainingArgs[0]; String outputFile = remainingArgs[1]; int numIterations = Integer.parseInt(remainingArgs[2]); long startTime = System.currentTimeMillis(); // Disable Spark logging. if (!enablingSparkLogging) { Logger.getLogger("org").setLevel(Level.OFF); Logger.getLogger("akka").setLevel(Level.OFF); } // Create and configure Spark context. SparkConf conf = new SparkConf().setAppName("Spark MPBoost learner"); JavaSparkContext sc = new JavaSparkContext(conf); // Create and configure learner. MpBoostLearner learner = new MpBoostLearner(sc); learner.setNumIterations(numIterations); if (cmd.hasOption("dp")) { learner.setNumDocumentsPartitions(Integer.parseInt(cmd.getOptionValue("dp"))); } if (cmd.hasOption("fp")) { learner.setNumFeaturesPartitions(Integer.parseInt(cmd.getOptionValue("fp"))); } if (cmd.hasOption("lp")) { learner.setNumLabelsPartitions(Integer.parseInt(cmd.getOptionValue("lp"))); } // Build classifier with MPBoost learner. BoostClassifier classifier = learner.buildModel(inputFile, labels0Based, binaryProblem); // Save classifier to disk. DataUtils.saveModel(sc, classifier, outputFile); long endTime = System.currentTimeMillis(); System.out.println("Execution time: " + (endTime - startTime) + " milliseconds."); }