List of usage examples for org.apache.commons.cli BasicParser BasicParser
BasicParser
From source file:edu.cornell.med.icb.geo.tools.CalculateRanks.java
private void proccess(final String[] args) throws IOException { // create the Options final Options options = new Options(); // help//from w w w.j a v a 2 s . co m options.addOption("h", "help", false, "print this message. This program compares the performance measures obtained " + "with each gene list and determines the rank of each gene list."); // input file name final Option inputOption = new Option("i", "input", true, "specify the path to the statistics file created by MicroarrayTrainEvaluate."); inputOption.setArgName("file"); inputOption.setRequired(true); options.addOption(inputOption); // output file name final Option outputOption = new Option("o", "output", true, "specify the destination file where post-processed statistics will be written"); outputOption.setArgName("file"); outputOption.setRequired(true); options.addOption(outputOption); // tallies file name final Option talliesOption = new Option("t", "tallies", true, "specify the file where tallies of rank per gene list will be written"); talliesOption.setArgName("file"); talliesOption.setRequired(false); options.addOption(talliesOption); // filter by shuffle test P-value final Option filterShuffleTestOption = new Option("f", "filter-shuffle-test", false, "indicate that only those results that pass the shuffle significance test should be used to calculate ranks and tallies."); filterShuffleTestOption.setRequired(false); options.addOption(filterShuffleTestOption); // parse the command line arguments CommandLine line = null; try { // create the command line parser final CommandLineParser parser = new BasicParser(); line = parser.parse(options, args, true); } catch (ParseException e) { System.err.println(e.getMessage()); usage(options); System.exit(1); } // print help and exit if (line.hasOption("h")) { usage(options); System.exit(0); } this.filterWithShuffleTest = line.hasOption("f"); if (this.filterWithShuffleTest) { System.out.println("Filtering classification results by shuffle test."); } postProcess(line.getOptionValue("i"), line.getOptionValue("o"), line.getOptionValue("t")); }
From source file:com.amazonaws.mturk.cmd.AbstractCmd.java
public void run(String[] args) { try {//from ww w. j a v a 2s . c o m BasicParser parser = new BasicParser(); CommandLine cmdLine = parser.parse(opt, args); if (cmdLine.hasOption(ARG_HELP) || cmdLine.hasOption(ARG_HELP_SHORT)) { printHelp(); System.exit(-1); } if (cmdLine.hasOption(ARG_SANDBOX) && !ClientConfig.SANDBOX_SERVICE_URL.equalsIgnoreCase(config.getServiceURL())) { log.info("Sandbox override"); setSandBoxMode(); } else { initService(); } log.debug(String.format("Running command against %s", config.getServiceURL())); runCommand(cmdLine); } catch (Exception e) { log.error("An error occurred: " + e.getLocalizedMessage(), e); System.exit(-1); } }
From source file:com.asakusafw.yaess.tools.Explain.java
static Configuration parseConfiguration(String[] args) throws ParseException { assert args != null; LOG.debug("Analyzing YAESS Explain arguments: {}", Arrays.toString(args)); CommandLineParser parser = new BasicParser(); CommandLine cmd = parser.parse(OPTIONS, args); String script = cmd.getOptionValue(OPT_SCRIPT.getOpt()); LOG.debug("Script: {}", script); Configuration result = new Configuration(); LOG.debug("Loading script: {}", script); try {/*from www . j a v a 2 s.c om*/ Properties properties = CommandLineUtil.loadProperties(new File(script)); result.script = BatchScript.load(properties); } catch (Exception e) { throw new IllegalArgumentException(MessageFormat.format("Invalid script \"{0}\".", script), e); } LOG.debug("Analyzed YAESS Explain arguments"); return result; }
From source file:edu.cornell.med.icb.geo.tools.GDS2InsightfulMiner.java
private void proccess(final String[] args) { // create the Options final Options options = new Options(); // help/*from w w w. j av a 2 s . c o m*/ options.addOption("h", "help", false, "print this message"); // input file name final Option inputOption = new Option("i", "input", true, "specify a GEO data set file (GDS file)"); inputOption.setArgName("file"); inputOption.setRequired(true); options.addOption(inputOption); // output file name final Option outputOption = new Option("o", "output", true, "specify the destination file"); outputOption.setArgName("file"); outputOption.setRequired(true); options.addOption(outputOption); // label values final Option labelOptions = new Option("l", "label", true, "specify a label to tag a set of columns"); labelOptions.setArgName("double-value"); labelOptions.setRequired(false); options.addOption(labelOptions); // group file names final Option groupOptions = new Option("g", "group", true, "specify a file that named columns associated to a label. Each -group option must match a -label option. Matching is done according to the order on the command line. Each line of the group file identifies a column in the GEO data set that is to be labeled according to the corresponding label"); groupOptions.setArgName("file"); groupOptions.setRequired(false); options.addOption(groupOptions); // default label value final Option defaultLabelOption = new Option("dl", "default-label", true, "Specify the label to use for columns that are not identified by -l -g pairs. Default value is zero."); groupOptions.setArgName("double-value"); groupOptions.setRequired(false); options.addOption(defaultLabelOption); // parse the command line arguments CommandLine line = null; double defaultLabelValue = 0; try { // create the command line parser final CommandLineParser parser = new BasicParser(); line = parser.parse(options, args, true); if ((line.hasOption("l") && !line.hasOption("g")) || (line.hasOption("g") && !line.hasOption("l"))) { System.err.println("Options -label and -group must be used together."); System.exit(10); } if (line.hasOption("l") && line.getOptionValues("l").length != line.getOptionValues("g").length) { System.err.println("The number of -label and -group options must match exactly."); System.exit(10); } if (line.hasOption("dl")) { defaultLabelValue = Double.parseDouble(line.getOptionValue("dl")); } } catch (ParseException e) { System.err.println(e.getMessage()); usage(options); System.exit(1); } // print help and exit if (line.hasOption("h")) { usage(options); System.exit(0); } try { final Map<Double, Set<String>> labels = readLabelGroups(line.getOptionValues("l"), line.getOptionValues("g")); //labels convert(line.getOptionValue("i"), line.getOptionValue("o"), labels, defaultLabelValue); System.exit(0); } catch (FileNotFoundException e) { System.err.println("Error opening file: \n"); printGroups(line); } catch (IOException e) { System.err.println("An error occurred reading one of the group files:\n"); printGroups(line); } }
From source file:com.asakusafw.yaess.tools.log.cli.Main.java
static Configuration parseConfiguration(String[] args) throws ParseException { assert args != null; LOG.debug("Analyzing arguments: {}", Arrays.toString(args)); CommandLineParser parser = new BasicParser(); CommandLine cmd = parser.parse(OPTIONS, args); ClassLoader classLoader = Main.class.getClassLoader(); YaessLogInput source = create(cmd, OPT_INPUT, YaessLogInput.class, classLoader); YaessLogOutput sink = create(cmd, OPT_OUTPUT, YaessLogOutput.class, classLoader); Map<String, String> sourceArgs = parseArgs(cmd, OPT_INPUT_ARGUMENT); Map<String, String> sinkArgs = parseArgs(cmd, OPT_OUTPUT_ARGUMENT); return new Configuration(source, sourceArgs, sink, sinkArgs); }
From source file:com.asakusafw.testdriver.tools.runner.BatchTestTruncator.java
static Conf parseArguments(String[] args) throws ParseException { assert args != null; CommandLineParser parser = new BasicParser(); CommandLine cmd = parser.parse(OPTIONS, args); Conf conf = new Conf(); String descriptionClass = cmd.getOptionValue(OPT_DESCRIPTION.getLongOpt()); Class<?> description;//from www.j av a 2 s. c o m try { description = Class.forName(descriptionClass); } catch (Exception e) { throw new IllegalArgumentException( MessageFormat.format(Messages.getString("BatchTestTruncator.errorFailedToAnalyze"), //$NON-NLS-1$ descriptionClass), e); } conf.context = new TestDriverContext(description); resolveDescription(conf, description); Properties arguments = cmd.getOptionProperties(OPT_ARGUMENT.getOpt()); conf.context.getBatchArgs().putAll(toMap(arguments)); Properties properties = cmd.getOptionProperties(OPT_PROPERTY.getOpt()); conf.context.getExtraConfigurations().putAll(toMap(properties)); return conf; }
From source file:com.github.cereda.sucuri.utils.CommandLineAnalyzer.java
/** * Parses the command line arguments./* w w w.ja v a 2 s. c o m*/ * * @return A boolean indicating if the parsing was successful. */ public boolean parse() { // create the options Option optVersion = new Option("v", "version", false, "print the application version"); Option optHelp = new Option("h", "help", false, "print the help message"); Option optReport = new Option("r", "report", false, "generate report"); Option optTemplate = new Option("t", "template", true, "set the master template"); Option optInput = new Option("i", "input", true, "set the input file"); Option optOutput = new Option("o", "output", true, "set the output file"); Option optEncoding = new Option("e", "encoding", true, "set the input encoding"); // add them commandLineOptions.addOption(optVersion); commandLineOptions.addOption(optHelp); commandLineOptions.addOption(optReport); commandLineOptions.addOption(optTemplate); commandLineOptions.addOption(optInput); commandLineOptions.addOption(optOutput); commandLineOptions.addOption(optEncoding); // create a new parser CommandLineParser parser = new BasicParser(); try { // parse the line CommandLine line = parser.parse(commandLineOptions, args); // check for help if (line.hasOption("help")) { printVersion(); printUsage(); return false; } else { // check for version if (line.hasOption("version")) { printVersion(); return false; } // check if there are anything else if (line.getArgs().length != 0) { printVersion(); printUsage(); return false; } else { // check for template if (line.hasOption("template")) { // check for input if (line.hasOption("input")) { // check for output if (line.hasOption("output")) { // get the report flag report = line.hasOption("report"); // check for encoding if (line.hasOption("encoding")) { encoding = line.getOptionValue("encoding"); } // set everything input = new File(line.getOptionValue("input")); output = new File(line.getOptionValue("output")); template = new File(line.getOptionValue("template")); return true; } else { printVersion(); System.out.println("The output file is required.".concat("\n")); printUsage(); return false; } } else { printVersion(); System.out.println("The input file is required.".concat("\n")); printUsage(); return false; } } else { printVersion(); System.out.println("The template file is required.".concat("\n")); printUsage(); return false; } } } } catch (ParseException parseException) { printVersion(); printUsage(); return false; } }
From source file:com.asakusafw.testdriver.tools.runner.BatchTestVerifier.java
static Conf parseArguments(String[] args) throws ParseException { assert args != null; CommandLineParser parser = new BasicParser(); CommandLine cmd = parser.parse(OPTIONS, args); Conf conf = new Conf(); String exporterClass = cmd.getOptionValue(OPT_EXPORTER.getLongOpt()); try {//from ww w . j a v a2s. c o m conf.exporter = Class.forName(exporterClass).asSubclass(ExporterDescription.class).newInstance(); } catch (Exception e) { throw new IllegalArgumentException( MessageFormat.format(Messages.getString("BatchTestVerifier.errorInvalidExporterDescription"), //$NON-NLS-1$ exporterClass), e); } conf.data = cmd.getOptionValue(OPT_DATA.getLongOpt()); conf.rule = cmd.getOptionValue(OPT_RULE.getLongOpt()); conf.context = new TestDriverContext(conf.exporter.getClass()); Properties arguments = cmd.getOptionProperties(OPT_ARGUMENT.getOpt()); conf.context.getBatchArgs().putAll(toMap(arguments)); Properties properties = cmd.getOptionProperties(OPT_PROPERTY.getOpt()); conf.context.getExtraConfigurations().putAll(toMap(properties)); return conf; }
From source file:com.comcast.oscar.cli.CommandRun.java
/** * Checks all the commands from the user. Order is IMPORTANT. Do not rearrange without full understanding. * @param args/* w w w . ja va2 s.c om*/ */ public void run(String[] args) { BasicParser parser = new BasicParser(); Options options = new Options(); BuildOptions.run(options); try { CommandLine line = parser.parse(options, args); HelpFormatter hf = new HelpFormatter(); hf.setWidth(180); hf.setLeftPadding(5); hf.setDescPadding(5); if (line.hasOption("h")) { hf.printHelp(Constants.OSCAR_CLI_USAGE, options); } if (line.hasOption("version")) { System.out.println(Constants.APACHE_20_LICENCE_DISCLAIMER); System.out.println(Constants.OSCAR_VERSION); } if (line.hasOption("s")) { comSpecification.setValues(line.getOptionValues("s")); if (comSpecification.getConfigurationFileType() == -1) { System.err.println(Specification.ERROR); System.exit(1); } if (comSpecification.getTlvDisassemble() == null) { System.err.println(Specification.ERROR); System.exit(1); } } if (line.hasOption("i")) { comInput = new Input(line.getOptionValues("i")); if (!comInput.hasInput()) { System.err.println(Input.ERROR); System.exit(1); } } if (line.hasOption("o")) { comOutput = new Output(line.getOptionValues("o")); } if (line.hasOption("k")) { comKey.setKey(line.getOptionValues("k")); } if (line.hasOption("mbb")) { comMergeBulk = new MergeBulk(line.getOptionValues("mbb")); if (comMergeBulk.hasInputDir()) { comMergeBulk.mergeFiles(comSpecification.getConfigurationFileType(), comKey.getKey()); } else { System.err.println(MergeBulk.ERROR); System.exit(1); } } if (line.hasOption("f")) { comFirmware = new Firmware(line.getOptionValues("f")); } if (line.hasOption("T")) { comTFTPServer = new TFTPServer(line.getOptionValues("T")); if (!comTFTPServer.hasAddress()) { System.err.println(TFTPServer.ERROR); System.exit(1); } } if (line.hasOption("m")) { comMaxCPE = new MaxCPE(line.getOptionValues("m")); } if (line.hasOption("df")) { comDownstreamFrequency = new DownstreamFrequency(line.getOptionValues("df")); } if (line.hasOption("cvc")) { comCVC = new CVC(line.getOptionValues("cvc")); if (!comCVC.hasCVC()) { System.err.println(CVC.ERROR); System.exit(1); } } if (line.hasOption("t")) { comTLV = new TLV(line.getOptionValues("t")); } if (line.hasOption("dm")) { comDigitmapInsert = new DigitmapInsert(line.getOptionValues("dm")); if (!comDigitmapInsert.hasDigitmap()) { System.err.println(DigitmapInsert.ERROR); System.exit(1); } } if (line.hasOption("O")) { comOID = new OID(line.getOptionValues("O")); if (!comOID.hasOID()) { System.err.println(OID.ERROR); System.exit(1); } } if (line.hasOption("d")) { comDecompile = new Decompile(line.getOptionValues("d")); decompile(); } if (line.hasOption("c")) { compile(); } if (line.hasOption("b")) { String[] optionValues = line.getOptionValues("b"); if (optionValues.length >= 3) { bulkBuild(optionValues[0]); bulkBuildCommand(new File(optionValues[1]), new File(optionValues[2])); } else if (optionValues.length >= 2) { bulkBuild(optionValues[0]); bulkBuildCommand(new File(optionValues[1])); } else { System.err.println(Constants.ERR_MIS_PAR); hf.printHelp(Constants.OSCAR_CLI_USAGE, options); } } if (line.hasOption("ftd")) { comFullTLVDisplay.printFullTLVDisplay(comSpecification.getConfigurationFileType()); } if (line.hasOption("x")) { comHexDisplay = new HexDisplay(line.getOptionValues("x")); if (comInput.hasInput()) { if (comInput.isBinary()) { comHexDisplay.printHexDisplayFromBinary(comInput.getInput()); } else { comHexDisplay.printHexDisplayFromText(comInput.getInput(), comSpecification.getConfigurationFileType()); } } else { System.err.println(Input.ERROR); System.exit(1); } } if (line.hasOption("j")) { if (comInput.hasInput()) { if (comInput.isBinary()) { comJSONDisplay.printJSONDisplayFromBinary(comInput.getInput(), comSpecification.getTlvDisassemble(), comSpecification.getConfigurationFileType()); } else { comJSONDisplay.printJSONDisplayFromText(comInput.getInput(), comSpecification.getTlvDisassemble()); } } else { System.err.println(Input.ERROR); System.exit(1); } } if (line.hasOption("ddm")) { if (comInput.hasInput()) { if (comInput.isBinary()) { comDigitmapDisplay.printDigitmapDisplayFromBinary(comInput.getInput()); } else { comDigitmapDisplay.printDigitmapDisplayFromText(comInput.getInput()); } } } if (line.hasOption("j2t")) { comJSONtoTLV = new JSONtoTLV(line.getOptionValues("j2t")); if (comJSONtoTLV.fileExists()) { comJSONtoTLV.printTLV(); } else { System.err.println(JSONtoTLV.ERROR); } } if (line.hasOption("t2j")) { comTLVtoJSON = new TLVtoJSON(line.getOptionValues("t2j")); comTLVtoJSON.printJSON(comSpecification.getTlvDisassemble()); } if (line.hasOption("td")) { comTLVDescription = new TLVDescription(line.getOptionValues("td")); comTLVDescription.printTLVDescription(comSpecification.getConfigurationFileType()); } if (line.hasOption("tr")) { comTranslate = new Translate(line.getOptionValues("tr")); comTranslate.translate(); } } catch (ParseException exp) { System.err.println("Parsing failed. Reason: " + exp.getMessage()); } }
From source file:cn.edu.pku.cbi.mosaichunter.MosaicHunter.java
private static boolean loadConfiguration(String[] args, String configFile) throws Exception { OptionBuilder.withArgName("file"); OptionBuilder.hasArg();/*from w w w . j a v a2 s. co m*/ OptionBuilder.withDescription("config file"); OptionBuilder.withLongOpt("config"); Option configFileOption = OptionBuilder.create("C"); OptionBuilder.withArgName("property=value"); OptionBuilder.hasArgs(2); OptionBuilder.withValueSeparator(); OptionBuilder.withDescription("properties that overrides the ones in config file"); OptionBuilder.withLongOpt("properties"); Option propertiesOption = OptionBuilder.create("P"); Options options = new Options(); options.addOption(configFileOption); options.addOption(propertiesOption); CommandLineParser parser = new BasicParser(); CommandLine cmd = null; try { cmd = parser.parse(options, args); } catch (ParseException pe) { System.out.println(pe.getMessage()); return false; } InputStream in = null; if (configFile == null || configFile.trim().isEmpty()) { configFile = cmd.getOptionValue("C"); if (configFile != null && new File(configFile).isFile()) { in = new FileInputStream(configFile); } } else { in = MosaicHunter.class.getClassLoader().getResourceAsStream(configFile); } if (in != null) { try { ConfigManager.getInstance().loadProperties(in); } catch (IOException ioe) { System.out.println("invalid config file: " + configFile); return false; } finally { in.close(); } } Properties properties = cmd.getOptionProperties("P"); if (properties != null) { ConfigManager.getInstance().putAll(properties); } return !ConfigManager.getInstance().getProperties().isEmpty(); }