List of usage examples for org.apache.commons.cli2.commandline Parser Parser
Parser
From source file:org.pharmgkb.util.CliHelper.java
/** * Parses arguments.//from w w w .j a v a 2 s. co m */ public void parse(String[] args) throws OptionException { m_options = m_groupBuilder.create(); Parser parser = new Parser(); parser.setGroup(m_options); parser.setHelpOption(m_helpOption); m_commandLine = parser.parse(args); }
From source file:org.rvsnoop.ui.RvSnoopApplication.java
private CommandLine parseCommandLine(String[] args, Option helpOption, Option projectOption) { Group group = new GroupBuilder().withOption(helpOption).withOption(projectOption).create(); Parser parser = new Parser(); parser.setGroup(group);/* w w w . ja va2 s.com*/ parser.setHelpOption(helpOption); parser.setHelpFormatter(new HelpFormatter()); CommandLine line = parser.parseAndHelp(args); if (line.hasOption(helpOption)) { System.exit(0); } return line; }
From source file:org.rzo.yajsw.WrapperExe.java
/** * Parses the command./*from w ww. j a v a 2 s . co m*/ * * @param args * the args */ private static void parseCommand(String[] args) { Parser parser = new Parser(); // configure a HelpFormatter HelpFormatter hf = new HelpFormatter(); DefaultOptionBuilder oBuilder = new DefaultOptionBuilder(); ; // configure a parser Parser p = new Parser(); p.setGroup(group); p.setHelpFormatter(hf); p.setHelpOption(oBuilder.withLongName("help").withShortName("?").create()); cl = p.parseAndHelp(args); // abort application if no CommandLine was parsed if (cl == null) { System.exit(-1); } cmds = cl.getOptions(); try { confFile = (String) cl.getValue(CONF_FILE); } catch (Exception ex) { System.out.println("no wrapper config file found "); } try { defaultFile = (String) cl.getValue(cl.getOption("-d")); if (defaultFile != null) defaultFile = new File(defaultFile).getCanonicalPath(); } catch (Exception ex) { // no defaults -> maybe ok } properties = cl.getValues(PROPERTIES); }
From source file:parse_wikipedia.ParseWikipedia.java
public static void main(String[] args) throws IOException { DefaultOptionBuilder obuilder = new DefaultOptionBuilder(); GroupBuilder gbuilder = new GroupBuilder(); Option dirInputPathOpt = DefaultOptionCreator.inputOption().create(); Option dirOutputPathOpt = DefaultOptionCreator.outputOption().create(); Group group = gbuilder.withName("Options").withOption(dirInputPathOpt).withOption(dirOutputPathOpt) .create();/*from w w w .j a va 2 s. co m*/ Parser parser = new Parser(); parser.setGroup(group); try { CommandLine cmdLine = parser.parse(args); String inputPath = (String) cmdLine.getValue(dirInputPathOpt); String outputPath = (String) cmdLine.getValue(dirOutputPathOpt); runJob(inputPath, outputPath); } catch (OptionException | InterruptedException | ClassNotFoundException e) { log.error("Exception", e); } }
From source file:tk.summerway.mahout9.tools.MyClusterDumper.java
private boolean buildParse(String[] args) { DefaultOptionBuilder obuilder = new DefaultOptionBuilder(); ArgumentBuilder abuilder = new ArgumentBuilder(); GroupBuilder gbuilder = new GroupBuilder(); Option inputDirOpt = DefaultOptionCreator.inputOption().create(); Option outputDirOpt = DefaultOptionCreator.outputOption().create(); Option outputFormatOpt = obuilder.withLongName(OUTPUT_FORMAT_OPT) .withArgument(abuilder.withName(OUTPUT_FORMAT_OPT).create()) .withDescription(//w w w. ja va 2s . c o m "The optional output format for the results. Options: TEXT, CSV, JSON or GRAPH_ML. Default is TEXT") .withShortName("of").create(); Option substringOpt = obuilder.withLongName(SUBSTRING_OPTION) .withArgument(abuilder.withName(SUBSTRING_OPTION).create()) .withDescription("The number of chars of the asFormatString() to print").withShortName("b") .create(); Option pointsDirOpt = obuilder.withLongName(POINTS_DIR_OPTION) .withArgument(abuilder.withName(POINTS_DIR_OPTION).create()) .withDescription( "The directory containing points sequence files mapping input vectors to their cluster. " + "If specified, then the program will output the points associated with a cluster") .withShortName("p").create(); Option samplePointsOpt = obuilder.withLongName(SAMPLE_POINTS) .withArgument(abuilder.withName(SAMPLE_POINTS).create()) .withDescription("Specifies the maximum number of points to include _per_ cluster. The default " + "is to include all points") .withShortName("sp").create(); Option dictionaryOpt = obuilder.withLongName(DICTIONARY_OPTION) .withArgument(abuilder.withName(DICTIONARY_OPTION).create()).withDescription("The dictionary file") .withShortName("d").create(); Option dictionaryTypeOpt = obuilder.withLongName(DICTIONARY_TYPE_OPTION) .withArgument(abuilder.withName(DICTIONARY_TYPE_OPTION).create()) .withDescription("The dictionary file type (text|sequencefile), default is text") .withShortName("dt").create(); Option numWordsOpt = obuilder.withLongName(NUM_WORDS_OPTION) .withArgument(abuilder.withName(NUM_WORDS_OPTION).create()) .withDescription("The number of top terms to print").withShortName("n").create(); Option evaluateOpt = obuilder.withLongName(EVALUATE_CLUSTERS) .withArgument(abuilder.withName(EVALUATE_CLUSTERS).create()) .withDescription("Run ClusterEvaluator and CDbwEvaluator over the input. " + "The output will be appended to the rest of the output at the end. Default is false.") .withShortName("e").create(); Option distanceMeasureOpt = obuilder.withLongName("distanceMeasure") .withArgument(abuilder.withName("distanceMeasure").create()) .withDescription("k-means distance measure class name").withShortName("dm").create(); Option helpOpt = obuilder.withLongName("help").withDescription("Print out help").withShortName("h") .create(); Group group = gbuilder.withName("Options").withOption(inputDirOpt).withOption(outputDirOpt) .withOption(outputFormatOpt).withOption(substringOpt).withOption(pointsDirOpt) .withOption(samplePointsOpt).withOption(dictionaryOpt).withOption(dictionaryTypeOpt) .withOption(numWordsOpt).withOption(evaluateOpt).withOption(distanceMeasureOpt).withOption(helpOpt) .create(); try { Parser parser = new Parser(); parser.setGroup(group); parser.setHelpOption(helpOpt); CommandLine cmdLine = parser.parse(args); if (cmdLine.hasOption(helpOpt)) { CommandLineUtil.printHelp(group); return false; } seqFileDir = getInputPath(); inputPath = getInputPath(); inputFile = getInputFile(); if (cmdLine.hasOption(inputDirOpt)) { seqFileDir = new Path(cmdLine.getValue(inputDirOpt).toString()); inputPath = new Path(cmdLine.getValue(inputDirOpt).toString()); inputFile = new File(cmdLine.getValue(inputDirOpt).toString()); } log.info("seqFileDir value: {}", seqFileDir); log.info("inputPath value: {}", inputPath); log.info("inputFile value: {}", inputFile); outputPath = getOutputPath(); outputFile = getOutputFile(); if (cmdLine.hasOption(outputDirOpt)) { outputPath = new Path(cmdLine.getValue(outputDirOpt).toString()); outputFile = new File(cmdLine.getValue(outputDirOpt).toString()); } log.info("outputPath value: {}", outputPath); log.info("outputFile value: {}", outputFile); if (cmdLine.hasOption(pointsDirOpt)) { pointsDir = new Path(cmdLine.getValue(pointsDirOpt).toString()); } log.info("pointsDir value: {}", pointsDir); if (cmdLine.hasOption(substringOpt)) { int sub = Integer.parseInt(cmdLine.getValue(substringOpt).toString()); if (sub >= 0) { subString = sub; } } log.info("subString value: {}", subString); termDictionary = cmdLine.getValue(dictionaryOpt).toString(); dictionaryFormat = cmdLine.getValue(dictionaryTypeOpt).toString(); log.info("termDictionary value: {}", termDictionary); log.info("dictionaryFormat value: {}", dictionaryFormat); if (cmdLine.hasOption(numWordsOpt)) { numTopFeatures = Integer.parseInt(cmdLine.getValue(numWordsOpt).toString()); } log.info("numTopFeatures value: {}", numTopFeatures); outputFormat = OUTPUT_FORMAT.TEXT; if (cmdLine.hasOption(outputFormatOpt)) { outputFormat = OUTPUT_FORMAT.valueOf(cmdLine.getValue(outputFormatOpt).toString()); } log.info("outputFormat value: {}", outputFormat); if (cmdLine.hasOption(samplePointsOpt)) { maxPointsPerCluster = Long.parseLong(cmdLine.getValue(samplePointsOpt).toString()); } else { maxPointsPerCluster = Long.MAX_VALUE; } log.info("maxPointsPerCluster value: {}", maxPointsPerCluster); runEvaluation = cmdLine.hasOption(evaluateOpt); log.info("runEvaluation value: {}", runEvaluation); String distanceMeasureClass = null; if (cmdLine.hasOption(distanceMeasureOpt)) { distanceMeasureClass = cmdLine.getValue(distanceMeasureOpt).toString(); } if (distanceMeasureClass != null) { measure = ClassUtils.instantiateAs(distanceMeasureClass, DistanceMeasure.class); } log.info("distanceMeasureClass value: {}", distanceMeasureClass); } catch (OptionException e) { CommandLineUtil.printHelp(group); log.error("parse para error", e); } return true; }