List of usage examples for org.apache.commons.cli BasicParser BasicParser
BasicParser
From source file:aco.Parse.java
static void parse_commandline(String args[], int runNumber) { if (args.length == 0) { System.err.println("No options are specified."); System.err.println("Try `--help' for more information."); System.exit(1);/*from w ww. ja va 2 s . com*/ } Options options = new Options(); options.addOption("u", "as", false, "apply basic Ant System"); options.addOption("z", "acs", false, "apply ant colony colony system"); CommandLine cmd = null; CommandLineParser parser = new BasicParser(); try { cmd = parser.parse(options, args); } catch (ParseException e) { System.err.println("Error: " + e.getMessage()); System.exit(1); } // Choice of ONE algorithm int algorithmCount = 0; if (cmd.hasOption("u")) { algorithmCount++; } if (cmd.hasOption("z")) { algorithmCount++; } if (algorithmCount > 1) { System.err.println("Error: More than one ACO algorithm enabled in the command line."); System.exit(1); } else if (algorithmCount == 1) { Ants.as_flag = false; Ants.acs_flag = false; } if (cmd.hasOption("u")) { Ants.as_flag = true; InOut.set_default_as_parameters(); System.out.println("\nRun basic Ant System #" + (runNumber + 1)); } if (cmd.hasOption("z")) { Ants.acs_flag = true; InOut.set_default_acs_parameters(); System.out.println("\nRun Ant Colony System #" + (runNumber + 1)); } }
From source file:com.medvision360.medrecord.tools.dumpadl.CommandLineReader.java
/** * Parse the command line options.//from ww w . j a va2 s. c o m * * @param args The command line arguments. */ public void parse(final String[] args) throws ParseException { final BasicParser parser = new BasicParser(); m_commandLine = parser.parse(m_options, args); }
From source file:com.graphaware.importer.cli.BaseCommandLineParser.java
private T produceConfig(String[] args, Options options) throws ParseException { CommandLine line = new BasicParser().parse(options, args); String graphDir = getMandatoryValue(line, "g"); String outputDir = getMandatoryValue(line, "o"); String props = getMandatoryValue(line, "r"); LOG.info("Producing import config:"); LOG.info("\tGraph: " + graphDir); LOG.info("\tOutput: " + outputDir); LOG.info("\tProps: " + props); return doProduceConfig(line, graphDir, outputDir, props); }
From source file:fastacreator.ParseCLI.java
/** * Rutger Ozinga. ParseCLI Parses the commandline input and is able to * return the wanted option and value./*from www . j av a 2 s .c o m*/ * * @param args are commandline arguments. * @throws org.apache.commons.cli.ParseException an exception */ public ParseCLI(final String[] args) throws org.apache.commons.cli.ParseException { HelpFormatter helpForm = new HelpFormatter(); Options cliOpt = new Options(); cliOpt.addOption("h", "help", false, "Displays help"); cliOpt.addOption("p", true, "Expects a path to a protein fasta file."); cliOpt.addOption("n", true, "Expects a path to place the new tab separated transcript file at."); cliOpt.addOption("i", true, "The index of the sequence"); if (args.length == 0) { helpForm.printHelp("Please enter all the " + "options below. ", cliOpt); System.exit(0); } else { BasicParser parser = new BasicParser(); CommandLine cliParser = parser.parse(cliOpt, args); if (cliParser.getOptions().length < 2) { System.out.println( "Error : " + "Please enter all options in" + " order for this program to work" + "!\n"); helpForm.printHelp("Please enter all of the " + "option ", cliOpt); System.exit(0); } else { if (cliParser.hasOption("h") && cliParser.hasOption("help")) { helpForm.printHelp("Command Line Help:\n", cliOpt); System.exit(0); } else { String snpFileString = cliParser.getOptionValue("p"); Path snpPath = Paths.get(snpFileString); if (Files.exists(snpPath)) { setCDSPath(snpPath); } else { System.out.println("The entered Path does" + " not exits"); helpForm.printHelp("Please enter -p followed by a valid" + " path ", cliOpt); System.exit(0); } String newFileString = cliParser.getOptionValue("n"); Matcher match2 = re.matcher(newFileString); String editedTranscriptFileString = match2.replaceAll(""); Path newFilePath = Paths.get(editedTranscriptFileString); if (Files.exists(newFilePath)) { setNewFilePath(newFileString); } else { System.out.println("The entered Path does" + " not exits"); helpForm.printHelp("Please enter -nt followed by a valid" + " path ", cliOpt); System.exit(0); } String indexString = cliParser.getOptionValue("i"); int index = Integer.parseInt(indexString); setIndex(index); } } } }
From source file:edu.brandeis.cs.develops.eptosql.Cli.java
public void parse() throws IOException { CommandLineParser parser = new BasicParser(); CodeGenerationOption cgo = CodeGenerationOption.UNNESTED; IROption iro = IROption.ENABLE;/*from w ww .j a va 2 s.c o m*/ CommandLine cmd = null; Scanner sc = null; try { cmd = parser.parse(options, args); } catch (ParseException e) { e.printStackTrace(); } if (cmd.hasOption("h")) help(); if (cmd.hasOption("nested")) cgo = CodeGenerationOption.NESTED; if (cmd.hasOption("disable_ir")) iro = IROption.DISABLE; if (cmd.hasOption("f")) { //log.log(Level.INFO, "Using cli argument -f=" + cmd.getOptionValue("f")); String filename = cmd.getOptionValue("f"); sc = new Scanner(new File(filename)); } else { sc = new Scanner(System.in); } String plan; while ((sc.hasNextLine())) { plan = sc.nextLine().trim(); if (plan.length() == 0) continue; System.out.println(EPtoSQL.syncCompile(cgo, iro, plan)); } sc.close(); }
From source file:cmdArgumentParser.CMDRetriever.java
public final String getResultDir(final String[] args) throws ParseException { CommandLineParser parser = new BasicParser(); CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("r") || cmd.hasOption("result_dir")) { if (new File(cmd.getOptionValue("r")).isDirectory()) { return cmd.getOptionValue("r"); } else {/*from w ww .j a va 2s .c om*/ HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("Please provide a valid directory to place the results in", options); System.exit(0); } } return "./"; }
From source file:com.wafflesoft.kinectcontroller.Cli.java
public CommandLine parse() { CommandLineParser parser = new BasicParser(); CommandLine cmd = null;/* ww w . j ava 2 s . c om*/ try { cmd = parser.parse(_options, _args); if (cmd.hasOption("h")) help(); if (cmd.hasOption("f")) { _logger.info("Using cli argument -f=" + cmd.getOptionValue("f")); // Whatever you want to do with the setting goes here System.out.println("Thank you for entering the config name"); } else { _logger.error("Missing configuration filename"); System.out.println("Warning: Missing configuration file."); help(); } } catch (ParseException e) { _logger.error("Failed to parse comand line properties", e); help(); } return cmd; }
From source file:com.punyal.replik8.Cli.java
public void parse() { CommandLineParser parser = new BasicParser(); CommandLine cmd = null;// w w w.j a v a2s .c o m try { cmd = parser.parse(options, args); if (cmd.hasOption("h")) help(); if (cmd.hasOption("u")) { if (cmd.hasOption("p")) setConfiguration(cmd.getOptionValue("u"), Integer.parseInt(cmd.getOptionValue("p"))); else setConfiguration(cmd.getOptionValue("u")); } else { help(); } } catch (ParseException e) { log.log(Level.SEVERE, "Failed to parse command line properties", e); } }
From source file:com.spectralogic.autogen.cli.CLI.java
private Arguments processArgs(final String[] args) throws Exception { final CommandLineParser parser = new BasicParser(); final CommandLine cmd = parser.parse(options, args); final String directory = cmd.getOptionValue("d"); final GeneratorType language = processLanguageArg(cmd); final String inputSpec = cmd.getOptionValue("i"); final boolean help = cmd.hasOption("h"); final boolean generateInternal = cmd.hasOption("internal"); final boolean noDoc = cmd.hasOption("no-doc"); final Arguments arguments = new Arguments(directory, language, inputSpec, help, generateInternal, noDoc); validateArguments(arguments);/*from w ww .java2 s .c o m*/ return arguments; }
From source file:com.c4om.jschematronvalidator.JSchematronValidatorMain.java
/** * Main method, executed at application startup * @param args CLI arguments (for more details, just run the program with the --help option). * @throws Exception if any exception is thrown anywhere *///from w w w.j av a 2 s. c o m public static void main(String[] args) throws Exception { LOGGER.info("Program starts"); CommandLine cmdLine; try { // create the command line parser CommandLineParser parser = new BasicParser(); // parse the command line arguments cmdLine = parser.parse(CMD_LINE_OPTIONS, args); } catch (ParseException e) { String fatalMessage = "Error at parsing command line: " + e.getMessage(); LOGGER.fatal(fatalMessage); System.err.println(fatalMessage); System.exit(1); return; //System.exit() makes this statement unreachable. However, 'return' is necessary to prevent the compiler from crying when I use 'cmdLine' outside the try-catch. } if (cmdLine.hasOption(CMD_LINE_OPTION_HELP)) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(CMD_LINE_SYNTAX, CMD_LINE_OPTIONS); System.exit(0); } if (!cmdLine.hasOption(CMD_LINE_OPTION_SCHEMATRON_FILE)) { System.err.println("Error at parsing command line: No input schematron is provided."); System.exit(1); } Document inputSchematronDocument = loadW3CDocumentFromInputFile( new File(cmdLine.getOptionValue(CMD_LINE_OPTION_SCHEMATRON_FILE))); Document candidateDocument; if (cmdLine.hasOption(CMD_LINE_OPTION_INPUT)) { try (InputStream candidateInputStream = new FileInputStream( new File(cmdLine.getOptionValue(CMD_LINE_OPTION_INPUT)))) { candidateDocument = loadW3CDocumentFromInputStream(candidateInputStream); } } else { candidateDocument = loadW3CDocumentFromInputStream(System.in); } String phase = cmdLine.getOptionValue(CMD_LINE_OPTION_PHASE); boolean allowForeign = cmdLine.hasOption(CMD_LINE_OPTION_ALLOW_FOREIGN); boolean diagnose = !cmdLine.hasOption(CMD_LINE_OPTION_SKIP_DIAGNOSE); boolean generatePaths = !cmdLine.hasOption(CMD_LINE_OPTION_SKIP_GENERATE_PATHS); boolean generateFiredRule = !cmdLine.hasOption(CMD_LINE_OPTION_SKIP_GENERATE_FIRED_RULE); boolean ignoreFileNotAvailableAtDocumentFunction = cmdLine .hasOption(CMD_LINE_OPTION_SKIP_OPTIONAL_FILES_ERRORS); ValidationMethod currentSchematronValidationMethod = new SaxonXSLT2BasedValidationMethod( ignoreFileNotAvailableAtDocumentFunction, allowForeign, diagnose, generatePaths, generateFiredRule); Document svrlResult = currentSchematronValidationMethod.performValidation(candidateDocument, inputSchematronDocument, phase); if (cmdLine.hasOption(CMD_LINE_OPTION_OUTPUT)) { OutputStream outputStream = new FileOutputStream( new File(cmdLine.getOptionValue(CMD_LINE_OPTION_OUTPUT))); printW3CDocumentToOutputStream(svrlResult, outputStream); } else { printW3CDocumentToOutputStream(svrlResult, System.out); } }