List of usage examples for org.apache.commons.cli HelpFormatter printHelp
public void printHelp(String cmdLineSyntax, Options options)
options
with the specified command line syntax. 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;// w w w .jav a2s . c om 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."); }
From source file:bboss.org.artofsolving.jodconverter.cli.Convert.java
public static void main(String[] arguments) throws ParseException, JSONException, IOException { CommandLineParser commandLineParser = new PosixParser(); CommandLine commandLine = commandLineParser.parse(OPTIONS, arguments); String outputFormat = null;/*w ww . ja va 2 s . co m*/ if (commandLine.hasOption(OPTION_OUTPUT_FORMAT.getOpt())) { outputFormat = commandLine.getOptionValue(OPTION_OUTPUT_FORMAT.getOpt()); } int port = DEFAULT_OFFICE_PORT; if (commandLine.hasOption(OPTION_PORT.getOpt())) { port = Integer.parseInt(commandLine.getOptionValue(OPTION_PORT.getOpt())); } String[] fileNames = commandLine.getArgs(); if ((outputFormat == null && fileNames.length != 2) || fileNames.length < 1) { String syntax = "java -jar jodconverter-core.jar [options] input-file output-file\n" + "or [options] -o output-format input-file [input-file...]"; HelpFormatter helpFormatter = new HelpFormatter(); helpFormatter.printHelp(syntax, OPTIONS); System.exit(STATUS_INVALID_ARGUMENTS); } DocumentFormatRegistry registry; if (commandLine.hasOption(OPTION_REGISTRY.getOpt())) { File registryFile = new File(commandLine.getOptionValue(OPTION_REGISTRY.getOpt())); registry = new JsonDocumentFormatRegistry(FileUtils.readFileToString(registryFile)); } else { registry = new DefaultDocumentFormatRegistry(); } DefaultOfficeManagerConfiguration configuration = new DefaultOfficeManagerConfiguration(); configuration.setPortNumber(port); if (commandLine.hasOption(OPTION_TIMEOUT.getOpt())) { int timeout = Integer.parseInt(commandLine.getOptionValue(OPTION_TIMEOUT.getOpt())); configuration.setTaskExecutionTimeout(timeout * 1000); } if (commandLine.hasOption(OPTION_USER_PROFILE.getOpt())) { String templateProfileDir = commandLine.getOptionValue(OPTION_USER_PROFILE.getOpt()); configuration.setTemplateProfileDir(new File(templateProfileDir)); } OfficeManager officeManager = configuration.buildOfficeManager(); officeManager.start(); OfficeDocumentConverter converter = new OfficeDocumentConverter(officeManager, registry); try { if (outputFormat == null) { File inputFile = new File(fileNames[0]); File outputFile = new File(fileNames[1]); converter.convert(inputFile, outputFile); } else { for (int i = 0; i < fileNames.length; i++) { File inputFile = new File(fileNames[i]); String outputName = FilenameUtils.getBaseName(fileNames[i]) + "." + outputFormat; File outputFile = new File(FilenameUtils.getFullPath(fileNames[i]) + outputName); converter.convert(inputFile, outputFile); } } } finally { officeManager.stop(); } }
From source file:com.boozallen.cognition.kom.KafakOffsetMonitor.java
public static void main(String[] args) { CommandLineParser parser = new DefaultParser(); CommandLine cmd = null;/*w w w. ja va2 s . c o m*/ try { cmd = parser.parse(options, args); } catch (ParseException e) { System.err.println(e.getMessage()); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("KafakOffsetMonitor", options); System.exit(1); } KafakOffsetMonitor monitor = new KafakOffsetMonitor(); monitor.zkHosts = cmd.getOptionValue("zkHosts"); monitor.zkRoot = cmd.getOptionValue("zkRoot", "/storm-kafka"); monitor.spoutId = cmd.getOptionValue("spoutId"); monitor.logstashHost = cmd.getOptionValue("logstashHost"); monitor.logstashPort = Integer.parseInt(cmd.getOptionValue("logstashPort")); int refresh = Integer.parseInt(cmd.getOptionValue("refresh", "15")); Timer timer = new Timer(); int period = refresh * 1000; int delay = 0; timer.schedule(monitor, delay, period); }
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 v a 2 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.metadave.stow.Stow.java
public static void main(String args[]) { System.out.println("Stow: StringTemplate Object Wrapper"); System.out.println("(C) 2014 Dave Parfitt"); System.out.println("Stow uses the Apache 2 license"); CommandLineParser parser = new BasicParser(); Options options = new Options(); //options.addOption( "a", "all", false, "do not hide entries starting with ."); Option javaPackage = new Option("java_package", "package for generated classes"); javaPackage.setArgs(1);/*from w ww . ja va 2 s . co m*/ //javaPackage.setRequired(true); Option destDir = new Option("dest", "destination directory for generated .java files"); destDir.setArgs(1); Option stgFile = new Option("stg", "StringTemplate4 group file"); stgFile.setArgs(1); Option classPrefix = new Option("class_prefix", "Prefix to use for generated classes"); classPrefix.setArgs(1); //destDir.setRequired(true); options.addOption(javaPackage); options.addOption(destDir); options.addOption(stgFile); options.addOption(classPrefix); try { CommandLine line = parser.parse(options, args); if (line.hasOption("java_package") && line.hasOption("dest") && line.hasOption("stg")) { generateObjects(line.getOptionValue("stg"), line.getOptionValue("java_package"), line.hasOption("class_prefix") ? line.getOptionValue("class_prefix") : "", line.getOptionValue("dest")); } else { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("stow", options); } } catch (ParseException exp) { System.out.println("Error parsing stow command line:" + exp.getMessage()); } }
From source file:edu.umd.cloud9.example.bigram.AnalyzeBigramCount.java
@SuppressWarnings({ "static-access" }) public static void main(String[] args) { Options options = new Options(); options.addOption(OptionBuilder.withArgName("path").hasArg().withDescription("input path").create(INPUT)); CommandLine cmdline = null;/*from w ww. ja va 2 s .c o m*/ 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)) { System.out.println("args: " + Arrays.toString(args)); HelpFormatter formatter = new HelpFormatter(); formatter.setWidth(120); formatter.printHelp(AnalyzeBigramCount.class.getName(), options); ToolRunner.printGenericCommandUsage(System.out); System.exit(-1); } String inputPath = cmdline.getOptionValue(INPUT); System.out.println("input path: " + inputPath); List<PairOfWritables<Text, IntWritable>> bigrams = SequenceFileUtils.readDirectory(new Path(inputPath)); Collections.sort(bigrams, new Comparator<PairOfWritables<Text, IntWritable>>() { public int compare(PairOfWritables<Text, IntWritable> e1, PairOfWritables<Text, IntWritable> e2) { if (e2.getRightElement().compareTo(e1.getRightElement()) == 0) { return e1.getLeftElement().compareTo(e2.getLeftElement()); } return e2.getRightElement().compareTo(e1.getRightElement()); } }); int singletons = 0; int sum = 0; for (PairOfWritables<Text, IntWritable> bigram : bigrams) { sum += bigram.getRightElement().get(); if (bigram.getRightElement().get() == 1) { singletons++; } } System.out.println("total number of unique bigrams: " + bigrams.size()); System.out.println("total number of bigrams: " + sum); System.out.println("number of bigrams that appear only once: " + singletons); System.out.println("\nten most frequent bigrams: "); Iterator<PairOfWritables<Text, IntWritable>> iter = Iterators.limit(bigrams.iterator(), 10); while (iter.hasNext()) { PairOfWritables<Text, IntWritable> bigram = iter.next(); System.out.println(bigram.getLeftElement() + "\t" + bigram.getRightElement()); } }
From source file:gr.demokritos.iit.demos.Demo.java
public static void main(String[] args) { try {//from w ww . j a v a 2 s .co m Options options = new Options(); options.addOption("h", HELP, false, "show help."); options.addOption("i", INPUT, true, "The file containing JSON " + " representations of tweets or SAG posts - 1 per line" + " default file looked for is " + DEFAULT_INFILE); options.addOption("o", OUTPUT, true, "Where to write the output " + " default file looked for is " + DEFAULT_OUTFILE); options.addOption("p", PROCESS, true, "Type of processing to do " + " ner for Named Entity Recognition re for Relation Extraction" + " default is NER"); options.addOption("s", SAG, false, "Whether to process as SAG posts" + " default is off - if passed means process as SAG posts"); CommandLineParser parser = new BasicParser(); CommandLine cmd = parser.parse(options, args); // DEFAULTS String filename = DEFAULT_INFILE; String outfilename = DEFAULT_OUTFILE; String process = NER; boolean isSAG = false; if (cmd.hasOption(HELP)) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("NER + RE extraction module", options); System.exit(0); } if (cmd.hasOption(INPUT)) { filename = cmd.getOptionValue(INPUT); } if (cmd.hasOption(OUTPUT)) { outfilename = cmd.getOptionValue(OUTPUT); } if (cmd.hasOption(SAG)) { isSAG = true; } if (cmd.hasOption(PROCESS)) { process = cmd.getOptionValue(PROCESS); } System.out.println(); System.out.println("Reading from file: " + filename); System.out.println("Process type: " + process); System.out.println("Processing SAG: " + isSAG); System.out.println("Writing to file: " + outfilename); System.out.println(); List<String> jsoni = new ArrayList(); Scanner in = new Scanner(new FileReader(filename)); while (in.hasNextLine()) { String json = in.nextLine(); jsoni.add(json); } PrintWriter writer = new PrintWriter(outfilename, "UTF-8"); System.out.println("Read " + jsoni.size() + " lines from " + filename); if (process.equalsIgnoreCase(RE)) { System.out.println("Running Relation Extraction"); System.out.println(); String json = API.RE(jsoni, isSAG); System.out.println(json); writer.print(json); } else { System.out.println("Running Named Entity Recognition"); System.out.println(); jsoni = API.NER(jsoni, isSAG); /* for(String json: jsoni){ NamedEntityList nel = NamedEntityList.fromJSON(json); nel.prettyPrint(); } */ for (String json : jsoni) { System.out.println(json); writer.print(json); } } writer.close(); } catch (ParseException | UnsupportedEncodingException | FileNotFoundException ex) { Logger.getLogger(Demo.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:io.github.gsteckman.doorcontroller.INA219Util.java
/** * Reads the Current from the INA219 with an I2C address and for a duration specified on the command line. * /*from www.j a v a2 s .c o m*/ * @param args * Command line arguments. * @throws IOException * If an error occurs reading/writing to the INA219 * @throws ParseException * If the command line arguments could not be parsed. */ public static void main(String[] args) throws IOException, ParseException { Options options = new Options(); options.addOption("addr", true, "I2C Address"); options.addOption("d", true, "Acquisition duration, in seconds"); options.addOption("bv", false, "Also read bus voltage"); options.addOption("sv", false, "Also read shunt voltage"); CommandLineParser parser = new DefaultParser(); CommandLine cmd = parser.parse(options, args); Address addr = Address.ADDR_40; if (cmd.hasOption("addr")) { int opt = Integer.parseInt(cmd.getOptionValue("addr"), 16); Address a = Address.getAddress(opt); if (a != null) { addr = a; } else { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("INA219Util", options); return; } } int duration = 0; if (cmd.hasOption("d")) { String opt = cmd.getOptionValue("d"); duration = Integer.parseInt(opt); } else { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("INA219Util", options); return; } boolean readBusVoltage = false; if (cmd.hasOption("bv")) { readBusVoltage = true; } boolean readShuntVoltage = false; if (cmd.hasOption("sv")) { readShuntVoltage = true; } INA219 i219 = new INA219(addr, 0.1, 3.2, INA219.Brng.V16, INA219.Pga.GAIN_8, INA219.Adc.BITS_12, INA219.Adc.SAMPLES_128); System.out.printf("Time\tCurrent"); if (readBusVoltage) { System.out.printf("\tBus"); } if (readShuntVoltage) { System.out.printf("\tShunt"); } System.out.printf("\n"); long start = System.currentTimeMillis(); do { try { System.out.printf("%d\t%f", System.currentTimeMillis() - start, i219.getCurrent()); if (readBusVoltage) { System.out.printf("\t%f", i219.getBusVoltage()); } if (readShuntVoltage) { System.out.printf("\t%f", i219.getShuntVoltage()); } System.out.printf("\n"); Thread.sleep(100); } catch (IOException e) { LOG.error("Exception while reading I2C bus", e); } catch (InterruptedException e) { break; } } while (System.currentTimeMillis() - start < duration * 1000); }
From source file:it.tizianofagni.sparkboost.AdaBoostMHLearnerExe.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 www . j a va 2 s .c o m String[] remainingArgs = null; try { cmd = parser.parse(options, args); remainingArgs = cmd.getArgs(); if (remainingArgs.length != 5) 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(AdaBoostMHLearnerExe.class.getSimpleName() + " [OPTIONS] <inputFile> <outputFile> <numIterations> <sparkMaster> <parallelismDegree>", 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]); String sparkMaster = remainingArgs[3]; int parallelismDegree = Integer.parseInt(remainingArgs[4]); 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 AdaBoost.MH learner"); JavaSparkContext sc = new JavaSparkContext(conf); // Create and configure learner. AdaBoostMHLearner learner = new AdaBoostMHLearner(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."); }
From source file:name.wagners.fssp.Main.java
/** * @param args//from w w w . jav a 2 s .co m * command-line arguments */ public static void main(final String[] args) { // create the command line parser CommandLineParser parser = new PosixParser(); // create the Options Options options = new Options(); options.addOption(OptionBuilder.hasArg().withArgName("gn").withLongOpt("generations") .withDescription("Number of generations [default: 50]").withType(Integer.valueOf(0)).create("g")); options.addOption(OptionBuilder.hasArg().withArgName("mp").withLongOpt("mutation") .withDescription("Mutation propability [default: 0.5]").withType(Double.valueOf(0)).create("m")); options.addOption(OptionBuilder.hasArg().withArgName("ps").withLongOpt("populationsize") .withDescription("Size of population [default: 20]").withType(Integer.valueOf(0)).create("p")); options.addOption(OptionBuilder.hasArg().withArgName("rp").withLongOpt("recombination") .withDescription("Recombination propability [default: 0.8]").withType(Double.valueOf(0)) .create("r")); options.addOption(OptionBuilder.hasArg().withArgName("sp").withLongOpt("selectionpressure") .withDescription("Selection pressure [default: 4]").withType(Integer.valueOf(0)).create("s")); options.addOption(OptionBuilder.withLongOpt("help").withDescription("print this message").create("h")); options.addOption(OptionBuilder.hasArg().withArgName("filename").isRequired().withLongOpt("file") .withDescription("Problem file [default: \"\"]").withType(String.valueOf("")).create("f")); options.addOptionGroup(new OptionGroup() .addOption(OptionBuilder.withLongOpt("verbose").withDescription("be extra verbose").create("v")) .addOption(OptionBuilder.withLongOpt("quiet").withDescription("be extra quiet").create("q"))); options.addOption(OptionBuilder.withLongOpt("version") .withDescription("print the version information and exit").create("V")); try { // parse the command line arguments CommandLine line = parser.parse(options, args); // validate that block-size has been set if (line.hasOption("h")) { // automatically generate the help statement HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("fssp", options); } } catch (MissingOptionException exp) { log.info("An option was missing:" + exp.getMessage(), exp); // automatically generate the help statement HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("fssp", options); } catch (MissingArgumentException exp) { log.info("An argument was missing:" + exp.getMessage(), exp); // automatically generate the help statement HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("fssp", options); } catch (AlreadySelectedException exp) { // automatically generate the help statement HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("fssp", options); } catch (ParseException exp) { log.info("Unexpected exception:" + exp.getMessage(), exp); // automatically generate the help statement HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("fssp", options); System.exit(1); } // Ausgabe der eingestellten Optionen log.info("Configuration"); // log.info(" Datafile: {}", fname); }