List of usage examples for org.apache.commons.cli2 CommandLine getValue
Object getValue(final Option option) throws IllegalStateException;
From source file:org.apache.mahout.utils.vectors.lucene.SeqFilePrint.java
public static void main(String[] args) throws OptionException { DefaultOptionBuilder obuilder = new DefaultOptionBuilder(); ArgumentBuilder abuilder = new ArgumentBuilder(); GroupBuilder gbuilder = new GroupBuilder(); Option inputOpt = obuilder.withLongName("inputFile").withRequired(true) .withArgument(abuilder.withName("inputFile").withMinimum(1).withMaximum(1).create()) .withDescription("The output of the dictionary as sequence file").withShortName("inputFile") .create();/*from ww w . j av a2 s. com*/ Option outFileOpt = obuilder.withLongName("outFile").withRequired(true) .withArgument(abuilder.withName("outfolder").withMinimum(1).withMaximum(1).create()) .withDescription("The output of the dictionary as sequence file").withShortName("outFile").create(); Group group = gbuilder.withName("Options").withOption(inputOpt).withOption(outFileOpt).create(); SeqFilePrint seqFilePrint = new SeqFilePrint(); Parser parser = new Parser(); parser.setGroup(group); CommandLine cmdLine = parser.parse(args); if (cmdLine.hasOption(inputOpt)) { seqFilePrint.setInputSeqFile(cmdLine.getValue(inputOpt).toString()); } if (cmdLine.hasOption(outFileOpt)) { seqFilePrint.setOutFile(cmdLine.getValue(outFileOpt).toString()); } try { seqFilePrint.run(args); } catch (Exception ex) { Logger.getLogger(SeqFilePrint.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:org.apache.mahout.vectorizer.SparseVectorsFromSequenceFiles.java
@Override public int run(String[] args) throws Exception { DefaultOptionBuilder obuilder = new DefaultOptionBuilder(); ArgumentBuilder abuilder = new ArgumentBuilder(); GroupBuilder gbuilder = new GroupBuilder(); Option inputDirOpt = DefaultOptionCreator.inputOption().create(); Option outputDirOpt = DefaultOptionCreator.outputOption().create(); Option minSupportOpt = obuilder.withLongName("minSupport") .withArgument(abuilder.withName("minSupport").withMinimum(1).withMaximum(1).create()) .withDescription("(Optional) Minimum Support. Default Value: 2").withShortName("s").create(); Option analyzerNameOpt = obuilder.withLongName("analyzerName") .withArgument(abuilder.withName("analyzerName").withMinimum(1).withMaximum(1).create()) .withDescription("The class name of the analyzer").withShortName("a").create(); Option chunkSizeOpt = obuilder.withLongName("chunkSize") .withArgument(abuilder.withName("chunkSize").withMinimum(1).withMaximum(1).create()) .withDescription("The chunkSize in MegaBytes. Default Value: 100MB").withShortName("chunk") .create();/* w w w . j av a2 s . c o m*/ Option weightOpt = obuilder.withLongName("weight").withRequired(false) .withArgument(abuilder.withName("weight").withMinimum(1).withMaximum(1).create()) .withDescription("The kind of weight to use. Currently TF or TFIDF. Default: TFIDF") .withShortName("wt").create(); Option minDFOpt = obuilder.withLongName("minDF").withRequired(false) .withArgument(abuilder.withName("minDF").withMinimum(1).withMaximum(1).create()) .withDescription("The minimum document frequency. Default is 1").withShortName("md").create(); Option maxDFPercentOpt = obuilder.withLongName("maxDFPercent").withRequired(false) .withArgument(abuilder.withName("maxDFPercent").withMinimum(1).withMaximum(1).create()) .withDescription( "The max percentage of docs for the DF. Can be used to remove really high frequency terms." + " Expressed as an integer between 0 and 100. Default is 99. If maxDFSigma is also set, " + "it will override this value.") .withShortName("x").create(); Option maxDFSigmaOpt = obuilder.withLongName("maxDFSigma").withRequired(false) .withArgument(abuilder.withName("maxDFSigma").withMinimum(1).withMaximum(1).create()) .withDescription( "What portion of the tf (tf-idf) vectors to be used, expressed in times the standard deviation (sigma) " + "of the document frequencies of these vectors. Can be used to remove really high frequency terms." + " Expressed as a double value. Good value to be specified is 3.0. In case the value is less " + "than 0 no vectors will be filtered out. Default is -1.0. Overrides maxDFPercent") .withShortName("xs").create(); Option minLLROpt = obuilder.withLongName("minLLR").withRequired(false) .withArgument(abuilder.withName("minLLR").withMinimum(1).withMaximum(1).create()) .withDescription("(Optional)The minimum Log Likelihood Ratio(Float) Default is " + LLRReducer.DEFAULT_MIN_LLR) .withShortName("ml").create(); Option numReduceTasksOpt = obuilder.withLongName("numReducers") .withArgument(abuilder.withName("numReducers").withMinimum(1).withMaximum(1).create()) .withDescription("(Optional) Number of reduce tasks. Default Value: 1").withShortName("nr") .create(); Option powerOpt = obuilder.withLongName("norm").withRequired(false) .withArgument(abuilder.withName("norm").withMinimum(1).withMaximum(1).create()) .withDescription( "The norm to use, expressed as either a float or \"INF\" if you want to use the Infinite norm. " + "Must be greater or equal to 0. The default is not to normalize") .withShortName("n").create(); Option logNormalizeOpt = obuilder.withLongName("logNormalize").withRequired(false) .withDescription("(Optional) Whether output vectors should be logNormalize. If set true else false") .withShortName("lnorm").create(); Option maxNGramSizeOpt = obuilder.withLongName("maxNGramSize").withRequired(false) .withArgument(abuilder.withName("ngramSize").withMinimum(1).withMaximum(1).create()) .withDescription("(Optional) The maximum size of ngrams to create" + " (2 = bigrams, 3 = trigrams, etc) Default Value:1") .withShortName("ng").create(); Option sequentialAccessVectorOpt = obuilder.withLongName("sequentialAccessVector").withRequired(false) .withDescription( "(Optional) Whether output vectors should be SequentialAccessVectors. If set true else false") .withShortName("seq").create(); Option namedVectorOpt = obuilder.withLongName("namedVector").withRequired(false) .withDescription("(Optional) Whether output vectors should be NamedVectors. If set true else false") .withShortName("nv").create(); Option overwriteOutput = obuilder.withLongName("overwrite").withRequired(false) .withDescription("If set, overwrite the output directory").withShortName("ow").create(); Option helpOpt = obuilder.withLongName("help").withDescription("Print out help").withShortName("h") .create(); Group group = gbuilder.withName("Options").withOption(minSupportOpt).withOption(analyzerNameOpt) .withOption(chunkSizeOpt).withOption(outputDirOpt).withOption(inputDirOpt).withOption(minDFOpt) .withOption(maxDFSigmaOpt).withOption(maxDFPercentOpt).withOption(weightOpt).withOption(powerOpt) .withOption(minLLROpt).withOption(numReduceTasksOpt).withOption(maxNGramSizeOpt) .withOption(overwriteOutput).withOption(helpOpt).withOption(sequentialAccessVectorOpt) .withOption(namedVectorOpt).withOption(logNormalizeOpt).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 -1; } Path inputDir = new Path((String) cmdLine.getValue(inputDirOpt)); Path outputDir = new Path((String) cmdLine.getValue(outputDirOpt)); int chunkSize = 100; if (cmdLine.hasOption(chunkSizeOpt)) { chunkSize = Integer.parseInt((String) cmdLine.getValue(chunkSizeOpt)); } int minSupport = 2; if (cmdLine.hasOption(minSupportOpt)) { String minSupportString = (String) cmdLine.getValue(minSupportOpt); minSupport = Integer.parseInt(minSupportString); } int maxNGramSize = 1; if (cmdLine.hasOption(maxNGramSizeOpt)) { try { maxNGramSize = Integer.parseInt(cmdLine.getValue(maxNGramSizeOpt).toString()); } catch (NumberFormatException ex) { log.warn("Could not parse ngram size option"); } } log.info("Maximum n-gram size is: {}", maxNGramSize); if (cmdLine.hasOption(overwriteOutput)) { HadoopUtil.delete(getConf(), outputDir); } float minLLRValue = LLRReducer.DEFAULT_MIN_LLR; if (cmdLine.hasOption(minLLROpt)) { minLLRValue = Float.parseFloat(cmdLine.getValue(minLLROpt).toString()); } log.info("Minimum LLR value: {}", minLLRValue); int reduceTasks = 1; if (cmdLine.hasOption(numReduceTasksOpt)) { reduceTasks = Integer.parseInt(cmdLine.getValue(numReduceTasksOpt).toString()); } log.info("Number of reduce tasks: {}", reduceTasks); Class<? extends Analyzer> analyzerClass = StandardAnalyzer.class; if (cmdLine.hasOption(analyzerNameOpt)) { String className = cmdLine.getValue(analyzerNameOpt).toString(); analyzerClass = Class.forName(className).asSubclass(Analyzer.class); // try instantiating it, b/c there isn't any point in setting it if // you can't instantiate it AnalyzerUtils.createAnalyzer(analyzerClass); } boolean processIdf; if (cmdLine.hasOption(weightOpt)) { String wString = cmdLine.getValue(weightOpt).toString(); if ("tf".equalsIgnoreCase(wString)) { processIdf = false; } else if ("tfidf".equalsIgnoreCase(wString)) { processIdf = true; } else { throw new OptionException(weightOpt); } } else { processIdf = true; } int minDf = 1; if (cmdLine.hasOption(minDFOpt)) { minDf = Integer.parseInt(cmdLine.getValue(minDFOpt).toString()); } int maxDFPercent = 99; if (cmdLine.hasOption(maxDFPercentOpt)) { maxDFPercent = Integer.parseInt(cmdLine.getValue(maxDFPercentOpt).toString()); } double maxDFSigma = -1.0; if (cmdLine.hasOption(maxDFSigmaOpt)) { maxDFSigma = Double.parseDouble(cmdLine.getValue(maxDFSigmaOpt).toString()); } float norm = PartialVectorMerger.NO_NORMALIZING; if (cmdLine.hasOption(powerOpt)) { String power = cmdLine.getValue(powerOpt).toString(); if ("INF".equals(power)) { norm = Float.POSITIVE_INFINITY; } else { norm = Float.parseFloat(power); } } boolean logNormalize = false; if (cmdLine.hasOption(logNormalizeOpt)) { logNormalize = true; } log.info("Tokenizing documents in {}", inputDir); Configuration conf = getConf(); Path tokenizedPath = new Path(outputDir, DocumentProcessor.TOKENIZED_DOCUMENT_OUTPUT_FOLDER); //TODO: move this into DictionaryVectorizer , and then fold SparseVectorsFrom with EncodedVectorsFrom // to have one framework for all of this. DocumentProcessor.tokenizeDocuments(inputDir, analyzerClass, tokenizedPath, conf); boolean sequentialAccessOutput = false; if (cmdLine.hasOption(sequentialAccessVectorOpt)) { sequentialAccessOutput = true; } boolean namedVectors = false; if (cmdLine.hasOption(namedVectorOpt)) { namedVectors = true; } boolean shouldPrune = maxDFSigma >= 0.0 || maxDFPercent > 0.00; String tfDirName = shouldPrune ? DictionaryVectorizer.DOCUMENT_VECTOR_OUTPUT_FOLDER + "-toprune" : DictionaryVectorizer.DOCUMENT_VECTOR_OUTPUT_FOLDER; log.info("Creating Term Frequency Vectors"); if (processIdf) { DictionaryVectorizer.createTermFrequencyVectors(tokenizedPath, outputDir, tfDirName, conf, minSupport, maxNGramSize, minLLRValue, -1.0f, false, reduceTasks, chunkSize, sequentialAccessOutput, namedVectors); } else { DictionaryVectorizer.createTermFrequencyVectors(tokenizedPath, outputDir, tfDirName, conf, minSupport, maxNGramSize, minLLRValue, norm, logNormalize, reduceTasks, chunkSize, sequentialAccessOutput, namedVectors); } Pair<Long[], List<Path>> docFrequenciesFeatures = null; // Should document frequency features be processed if (shouldPrune || processIdf) { log.info("Calculating IDF"); docFrequenciesFeatures = TFIDFConverter.calculateDF(new Path(outputDir, tfDirName), outputDir, conf, chunkSize); } long maxDF = maxDFPercent; //if we are pruning by std dev, then this will get changed if (shouldPrune) { long vectorCount = docFrequenciesFeatures.getFirst()[1]; if (maxDFSigma >= 0.0) { Path dfDir = new Path(outputDir, TFIDFConverter.WORDCOUNT_OUTPUT_FOLDER); Path stdCalcDir = new Path(outputDir, HighDFWordsPruner.STD_CALC_DIR); // Calculate the standard deviation double stdDev = BasicStats.stdDevForGivenMean(dfDir, stdCalcDir, 0.0, conf); maxDF = (int) (100.0 * maxDFSigma * stdDev / vectorCount); } long maxDFThreshold = (long) (vectorCount * (maxDF / 100.0f)); // Prune the term frequency vectors Path tfDir = new Path(outputDir, tfDirName); Path prunedTFDir = new Path(outputDir, DictionaryVectorizer.DOCUMENT_VECTOR_OUTPUT_FOLDER); Path prunedPartialTFDir = new Path(outputDir, DictionaryVectorizer.DOCUMENT_VECTOR_OUTPUT_FOLDER + "-partial"); log.info("Pruning"); if (processIdf) { HighDFWordsPruner.pruneVectors(tfDir, prunedTFDir, prunedPartialTFDir, maxDFThreshold, minDf, conf, docFrequenciesFeatures, -1.0f, false, reduceTasks); } else { HighDFWordsPruner.pruneVectors(tfDir, prunedTFDir, prunedPartialTFDir, maxDFThreshold, minDf, conf, docFrequenciesFeatures, norm, logNormalize, reduceTasks); } HadoopUtil.delete(new Configuration(conf), tfDir); } if (processIdf) { TFIDFConverter.processTfIdf(new Path(outputDir, DictionaryVectorizer.DOCUMENT_VECTOR_OUTPUT_FOLDER), outputDir, conf, docFrequenciesFeatures, minDf, maxDF, norm, logNormalize, sequentialAccessOutput, namedVectors, reduceTasks); } } catch (OptionException e) { log.error("Exception", e); CommandLineUtil.printHelp(group); } return 0; }
From source file:org.mzd.shap.spring.cli.ExportData.java
@Override @SuppressWarnings("unchecked") public void execute(String[] args) { try {/*from w ww.j a v a2 s . c om*/ CommandLine cl = getApp().parseArguments(args); String[] xmlPath = { "datasource-context.xml", "service-context.xml", "orm-context.xml" }; getApp().startApplication(xmlPath, true); // Target DomainTarget target = null; if (cl.hasOption(SAMPLE_ID)) { target = DomainTarget.SAMPLE; } else if (cl.hasOption(SEQUENCE_ID)) { target = DomainTarget.SEQUENCE; } else if (cl.hasOption(FEATURE_ID)) { target = DomainTarget.FEATURE; } else if (cl.hasOption(REF_BY_ASSOC)) { target = DomainTarget.DEFERRED; } // Taxonomy filter List<Taxonomy> excludedTaxa = new ArrayList<Taxonomy>(); if (cl.hasOption(TAXON)) { for (Object obj : cl.getValues(TAXON)) { try { excludedTaxa.add(Taxonomy.valueOf(((String) obj).toUpperCase())); } catch (IllegalArgumentException ex) { throw new ApplicationException("Unknown taxon name [" + obj + "]", ex); } } } // Source List<String> idList = null; if (cl.hasOption(LIST)) { idList = cl.getValues(LIST); } else if (cl.hasOption(INPUT_FILE)) { idList = readIdFile((File) cl.getValue(INPUT_FILE)); } // Destination File outputFile = (File) cl.getValue(OUTPUT_FILE); if (outputFile.exists()) { throw new IOException("Output file [" + outputFile.getPath() + "] already exists"); } // Format if (cl.hasOption(ANNOTATION)) { writeAnnotation(target, idList, excludedTaxa, outputFile); } else if (cl.hasOption(FASTA)) { writeFasta(target, cl.hasOption(FASTA_FEATURES), cl.hasOption(FEATURE_TRANSLATE), cl.hasOption(FASTA_LONG_HEADER), idList, excludedTaxa, outputFile); } else if (cl.hasOption(GENBANK)) { writeGenbank(target, idList, excludedTaxa, outputFile); } // else if (cl.hasOption(HISTOGRAM)) { // writeHistogram( // target, // (String)cl.getValue(HISTOGRAM_ANNOTATOR), // idList, // (Double)cl.getValue(HISTOGRAM_CONFIDENCE), // excludedTaxa, // outputFile); // } } catch (Throwable t) { System.err.println(t.getMessage()); System.exit(1); } }
From source file:org.mzd.shap.spring.cli.ImportData.java
@Override public void execute(String[] args) { try {/* w ww. j a v a2 s.c om*/ CommandLine cl = getApp().parseArguments(args); String[] xmlPath = { "datasource-context.xml", "service-context.xml", "orm-context.xml" }; getApp().startApplication(xmlPath, true); // Add an observer to show simply progress activity. this.dataAdminService = (DataAdminService) getApp().getContext().getBean("dataAdminService"); if (cl.hasOption(SET_COVERAGE)) { String projectName = (String) cl.getValue(PROJECT); String sampleName = (String) cl.getValue(SAMPLE); File inputFile = (File) cl.getValue(SET_COVERAGE); setCoverage(projectName, sampleName, inputFile); } else if (cl.hasOption(IMPORT_SEQUENCE)) { String projectName = (String) cl.getValue(PROJECT); String sampleName = (String) cl.getValue(SAMPLE); File inputFile = (File) cl.getValue(IMPORT_SEQUENCE); getDataAdminService().addSequencesFromFasta(projectName, sampleName, inputFile); } else if (cl.hasOption(ADD_PROJECT)) { String projectName = (String) cl.getValue(PROJECT); String description = CommandLineApplication.concatenateValues(cl.getValues(DESCRIPTION)); System.out.println("Adding project [" + projectName + "] [" + description + "]"); getDataAdminService().addProject(projectName, description); } else if (cl.hasOption(ADD_SAMPLE)) { String sampleName = (String) cl.getValue(SAMPLE); String projectName = (String) cl.getValue(PROJECT); String description = CommandLineApplication.concatenateValues(cl.getValues(DESCRIPTION)); System.out.println( "Adding sample [" + sampleName + "] [" + description + "] to [" + projectName + "]"); getDataAdminService().addSample(projectName, sampleName, description); } else if (cl.hasOption(ADD_SEQUENCE)) { String sampleName = (String) cl.getValue(SAMPLE); String projectName = (String) cl.getValue(PROJECT); String sequenceName = (String) cl.getValue(SEQUENCE); String description = CommandLineApplication.concatenateValues(cl.getValues(DESCRIPTION)); System.out.println("Adding container sequence [" + sequenceName + "] [" + description + "] to [" + projectName + "," + sampleName + "]"); getDataAdminService().addSequence(projectName, sampleName, sequenceName, description); } else if (cl.hasOption(IMPORT_SEQUENCE_XML)) { String sampleName = (String) cl.getValue(SAMPLE); String projectName = (String) cl.getValue(PROJECT); String detectorName = (String) cl.getValue(DETECTOR); File inputFile = (File) cl.getValue(IMPORT_SEQUENCE_XML); System.out.println("Importing sequences from XML to [" + projectName + "," + sampleName + "] registered to detector [" + detectorName + "]"); getDataAdminService().addSequencesFromXml(projectName, sampleName, detectorName, inputFile); } else if (cl.hasOption(IMPORT_FEATURE_XML)) { String sampleName = (String) cl.getValue(SAMPLE); String projectName = (String) cl.getValue(PROJECT); String sequenceName = (String) cl.getValue(SEQUENCE); String detectorName = (String) cl.getValue(DETECTOR); File inputFile = (File) cl.getValue(IMPORT_FEATURE_XML); System.out.println("Importing features from XML to [" + projectName + "," + sampleName + "," + sequenceName + "] " + "registered to detector [" + detectorName + "]"); getDataAdminService().addFeaturesFromXml(projectName, sampleName, sequenceName, detectorName, inputFile); } else if (cl.hasOption(REMOVE_SEQUENCE)) { File inputFile = (File) cl.getValue(REMOVE_SEQUENCE); removeSequence(inputFile); } else if (cl.hasOption(REMOVE_FEATURE)) { File inputFile = (File) cl.getValue(REMOVE_FEATURE); removeFeature(inputFile); } } catch (Throwable t) { System.err.println(t.getMessage()); System.exit(1); } }
From source file:org.mzd.shap.spring.cli.JobControl.java
public void execute(String[] args) { try {//from ww w . j a va 2s.c o m CommandLine cl = getApp().parseArguments(args); String[] xmlPath = { "delegate-context.xml", "datasource-context.xml", "task-context.xml", "service-context.xml", "orm-context.xml" }; getApp().startApplication(xmlPath, true); batchAdminService = (BatchAdminService) getApp().getContext().getBean("batchAdminService"); jobDaemon = (JobDaemon) getApp().getContext().getBean("jobDaemon"); if (cl.hasOption(SUBMIT)) { File inputXml = (File) cl.getValue(SUBMIT); PlanIO beanIO = new PlanIOXstream(); Plan plan = beanIO.read(inputXml); submitAndWait(plan); } else if (cl.hasOption(RESTART)) { restartAndWait(); } } catch (Throwable t) { System.err.println(t.getMessage()); System.exit(1); } }
From source file:org.mzd.shap.spring.cli.UserControl.java
@Override public void execute(String[] args) { try {/* w w w . j a va2 s . c om*/ CommandLine cl = getApp().parseArguments(args); String[] xmlPath = { "datasource-context.xml", "service-context.xml", "orm-context.xml" }; getApp().startApplication(xmlPath, true); UserAdminService userService = (UserAdminService) getApp().getContext() .getBean("localUserDetailsService"); if (cl.hasOption(CREATE)) { UserView user; if (cl.hasOption(ADMIN)) { user = UserView.createAdminUser((String) cl.getValue(NAME), (String) cl.getValue(USERNAME), (String) cl.getValue(PASSWORD)); } else { user = UserView.createUser((String) cl.getValue(NAME), (String) cl.getValue(USERNAME), (String) cl.getValue(PASSWORD)); } validate(user); userService.createUser(user); } else if (cl.hasOption(DELETE)) { userService.deleteUser((String) cl.getValue(USERNAME)); } } catch (Throwable t) { System.err.println(t.getMessage()); System.exit(1); } }
From source file:org.opencloudengine.flamingo.mapreduce.core.AbstractJob.java
/** * ?? ? Hadoop Configuration ?? ? ? ??. * {@code addInputOption} ? {@code addOutputOption} * ?? ? Hadoop Configuration? ? ?? * {@code OptionException}? ?. ? Hadoop Configuration ? * {@code inputPath} ? {@code outputPath}? * <tt>non-null</tt> . ?? ? Hadoop Configuration ? * .//w w w . jav a 2 s . c o m * * @param cmdLine ?? * @throws IllegalArgumentException inputOption ? {@code --input} {@code -Dmapred.input dir} ?? , outputOption ? {@code --output} {@code -Dmapred.output dir} ?? , */ protected void parseDirectories(CommandLine cmdLine) { Configuration conf = getConf(); if (inputOption != null && cmdLine.hasOption(inputOption)) { this.inputPath = new Path(cmdLine.getValue(inputOption).toString()); } if (inputPath == null && conf.get("mapred.input.dir") != null) { this.inputPath = new Path(conf.get("mapred.input.dir")); } if (outputOption != null && cmdLine.hasOption(outputOption)) { this.outputPath = new Path(cmdLine.getValue(outputOption).toString()); } if (outputPath == null && conf.get("mapred.output.dir") != null) { this.outputPath = new Path(conf.get("mapred.output.dir")); } // Temporary Path . ? CLASSPATH? <tt>flamingo-hadoop-site.xml</tt> ?? ? . if (tempPath == null && conf.get("tempDir") != null) { this.tempPath = new Path(conf.get("tempDir")); } Preconditions.checkArgument(inputOption == null || inputPath != null, " ? -Dmapred.input.dir ? ? . -Dmapred.input.dir ? ? ? ? ? ."); Preconditions.checkArgument(outputOption == null || outputPath != null, " ? -Dmapred.output.dir ? ? . -Dmapred.input.dir ? ? ? ? ? ."); }
From source file:org.opencloudengine.flamingo.mapreduce.core.AbstractJob.java
protected static void maybePut(Map<String, String> args, CommandLine cmdLine, Option... opt) { for (Option o : opt) { // ??? ? ? ? if (cmdLine.hasOption(o) || cmdLine.getValue(o) != null) { // ??? ? ? OK // nulls are ok, for cases where options are simple flags. Object vo = cmdLine.getValue(o); String value = vo == null ? null : vo.toString(); args.put(o.getPreferredName(), value); }// ww w . java 2 s . c om } }
From source file:org.rvsnoop.ui.RvSnoopApplication.java
private File loadProjectIfValid(Option project, CommandLine line) { if (!line.hasOption(project)) { return null; }//from ww w .java 2 s . c om String filename = line.getValue(project).toString(); if (filename == null || filename.length() == 0) { logger.warn(getString("CLI.warn.noProject")); return null; } File file = new File(filename); if (!file.canRead()) { logger.error(getString("CLI.error.unreadableProject"), filename); return null; } return file; }
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();/*w w w .j a v a 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); } }