List of usage examples for org.apache.commons.cli MissingArgumentException getOption
public Option getOption()
From source file:com.galenframework.actions.GalenActionConfigArguments.java
public static GalenActionConfigArguments parse(String[] args) { args = ArgumentsUtils.processSystemProperties(args); Options options = new Options(); options.addOption("g", "global", false, "Flag to create global config in user home directory"); CommandLineParser parser = new PosixParser(); CommandLine cmd;//from w w w . ja v a 2 s . com try { cmd = parser.parse(options, args); } catch (MissingArgumentException e) { throw new IllegalArgumentException("Missing value for " + e.getOption().getLongOpt(), e); } catch (Exception ex) { throw new RuntimeException(ex); } GalenActionConfigArguments configArguments = new GalenActionConfigArguments(); configArguments.isGlobal = cmd.hasOption("g"); return configArguments; }
From source file:com.galenframework.ide.model.settings.IdeArguments.java
public static IdeArguments parse(String[] args) { Options options = new Options(); options.addOption("h", "help", false, "Print this message"); options.addOption("p", "port", true, "Port for a server"); options.addOption("P", "profile", true, "Profile that will be loaded on start"); options.addOption("s", "storage", true, "Path to static file storage that will be used for storing reports"); options.addOption("k", "keep-results", true, "Amount of last results to be kept"); options.addOption("c", "cleanup-period", true, "Period in minutes in which it should run task cleanups"); options.addOption("z", "zombie-results-timeout", true, "Minutes for how long it should keep unfinished results"); CommandLineParser parser = new PosixParser(); CommandLine cmd;//from ww w. j a va 2s . c o m try { cmd = parser.parse(options, args); } catch (MissingArgumentException e) { throw new IllegalArgumentException("Missing value for " + e.getOption().getLongOpt(), e); } catch (Exception ex) { throw new RuntimeException(ex); } if (cmd.hasOption("h")) { printHelp(options); System.exit(0); } IdeArguments ideArguments = new IdeArguments(); ideArguments.setProfile(cmd.getOptionValue("P")); ideArguments.setPort(Integer.parseInt(cmd.getOptionValue("p", "4567"))); ideArguments.setFileStorage(cmd.getOptionValue("s")); ideArguments.setKeepLastResults(Integer.parseInt(cmd.getOptionValue("k", "30"))); ideArguments.setCleanupPeriodInMinutes(Integer.parseInt(cmd.getOptionValue("c", "1"))); return ideArguments; }
From source file:com.galenframework.actions.GalenActionDumpArguments.java
public static GalenActionDumpArguments parse(String[] args) { args = ArgumentsUtils.processSystemProperties(args); Options options = new Options(); options.addOption("u", "url", true, "Initial test url"); options.addOption("s", "size", true, "Browser window size"); options.addOption("W", "max-width", true, "Maximum width of element area image"); options.addOption("H", "max-height", true, "Maximum height of element area image"); options.addOption("E", "export", true, "Export path for page dump"); CommandLineParser parser = new PosixParser(); CommandLine cmd = null;//w w w. ja va 2 s . c om try { cmd = parser.parse(options, args); } catch (MissingArgumentException e) { throw new IllegalArgumentException("Missing value for " + e.getOption().getLongOpt(), e); } catch (Exception ex) { throw new RuntimeException(ex); } GalenActionDumpArguments arguments = new GalenActionDumpArguments(); arguments.setUrl(cmd.getOptionValue("u")); arguments.setScreenSize(convertScreenSize(cmd.getOptionValue("s"))); arguments.setMaxWidth(parseOptionalInt(cmd.getOptionValue("W"))); arguments.setMaxHeight(parseOptionalInt(cmd.getOptionValue("H"))); arguments.setExport(cmd.getOptionValue("E")); String[] leftovers = cmd.getArgs(); List<String> paths = new LinkedList<String>(); if (leftovers.length > 0) { for (int i = 0; i < leftovers.length; i++) { paths.add(leftovers[i]); } } arguments.setPaths(paths); return arguments; }
From source file:com.galenframework.actions.GalenActionCheckArguments.java
public static GalenActionCheckArguments parse(String[] args) { args = ArgumentsUtils.processSystemProperties(args); Options options = new Options(); options.addOption("i", "include", true, "Tags for sections that should be included in test run"); options.addOption("e", "exclude", true, "Tags for sections that should be excluded from test run"); options.addOption("h", "htmlreport", true, "Path for html output report"); options.addOption("j", "jsonreport", true, "Path for json report"); options.addOption("g", "testngreport", true, "Path for testng xml report"); options.addOption("u", "url", true, "Initial test url"); options.addOption("s", "size", true, "Browser window size"); options.addOption("J", "javascript", true, "JavaScript code that should be executed before checking layout"); CommandLineParser parser = new PosixParser(); CommandLine cmd = null;/*from w w w . j a v a2s . c o m*/ try { cmd = parser.parse(options, args); } catch (MissingArgumentException e) { throw new IllegalArgumentException("Missing value for " + e.getOption().getLongOpt(), e); } catch (Exception ex) { throw new RuntimeException(ex); } GalenActionCheckArguments arguments = new GalenActionCheckArguments(); arguments.setTestngReport(cmd.getOptionValue("g")); arguments.setHtmlReport(cmd.getOptionValue("h")); arguments.setJsonReport(cmd.getOptionValue("j")); arguments.setUrl(cmd.getOptionValue("u")); arguments.setScreenSize(convertScreenSize(cmd.getOptionValue("s"))); arguments.setJavascript(cmd.getOptionValue("J")); arguments.setIncludedTags(convertTags(cmd.getOptionValue("i"))); arguments.setExcludedTags(convertTags(cmd.getOptionValue("e"))); String[] leftovers = cmd.getArgs(); List<String> paths = new LinkedList<String>(); if (leftovers.length > 0) { for (int i = 0; i < leftovers.length; i++) { paths.add(leftovers[i]); } } arguments.setPaths(paths); if (paths.isEmpty()) { throw new IllegalArgumentException("Missing spec files"); } return arguments; }
From source file:com.galenframework.actions.GalenActionTestArguments.java
public static GalenActionTestArguments parse(String[] args) { args = ArgumentsUtils.processSystemProperties(args); Options options = new Options(); options.addOption("i", "include", true, "Tags for sections that should be included in test run"); options.addOption("e", "exclude", true, "Tags for sections that should be excluded from test run"); options.addOption("h", "htmlreport", true, "Path for html output report"); options.addOption("j", "jsonreport", true, "Path for json report"); options.addOption("g", "testngreport", true, "Path for testng xml report"); options.addOption("r", "recursive", false, "Flag for recursive tests scan"); options.addOption("p", "parallel-tests", true, "Amount of tests to be run in parallel"); options.addOption("P", "parallel-suites", true, "Amount of tests to be run in parallel"); options.addOption("f", "filter", true, "Test filter"); options.addOption("G", "groups", true, "Test groups"); options.addOption("Q", "excluded-groups", true, "Excluded test groups"); CommandLineParser parser = new PosixParser(); CommandLine cmd = null;//from w ww. j av a 2s . c om try { cmd = parser.parse(options, args); } catch (MissingArgumentException e) { throw new IllegalArgumentException("Missing value for " + e.getOption().getLongOpt(), e); } catch (Exception ex) { throw new RuntimeException(ex); } GalenActionTestArguments arguments = new GalenActionTestArguments(); arguments.setIncludedTags(convertTags(cmd.getOptionValue("i", ""))); arguments.setExcludedTags(convertTags(cmd.getOptionValue("e", ""))); arguments.setTestngReport(cmd.getOptionValue("g")); arguments.setRecursive(cmd.hasOption("r")); arguments.setHtmlReport(cmd.getOptionValue("h")); /* having this double check in order to have backwards compatibility with previous version in which the parallel tests used to be defined via --parallel-suites argument */ if (cmd.hasOption("p")) { arguments.setParallelThreads(Integer.parseInt(cmd.getOptionValue("p", "0"))); } else { arguments.setParallelThreads(Integer.parseInt(cmd.getOptionValue("P", "0"))); } arguments.setFilter(cmd.getOptionValue("f")); arguments.setJsonReport(cmd.getOptionValue("j")); arguments.setGroups(convertTags(cmd.getOptionValue("G"))); arguments.setExcludedGroups(convertTags(cmd.getOptionValue("Q"))); String[] leftovers = cmd.getArgs(); List<String> paths = new LinkedList<String>(); if (leftovers.length > 0) { for (int i = 0; i < leftovers.length; i++) { paths.add(leftovers[i]); } } arguments.setPaths(paths); if (paths.isEmpty()) { throw new IllegalArgumentException("Missing test files"); } return arguments; }
From source file:jp.andeb.obbutil.ObbUtilMain.java
private static boolean doAdd(String[] args) { final CommandLine commandLine; try {//from w ww . ja v a 2 s . com final CommandLineParser parser = new GnuParser(); commandLine = parser.parse(OPTIONS_FOR_ADD, args); } catch (MissingArgumentException e) { System.err.println("??????: " + e.getOption().getOpt()); printUsage(PROGNAME); return false; } catch (MissingOptionException e) { System.err.println("??????: " + e.getMissingOptions()); printUsage(PROGNAME); return false; } catch (UnrecognizedOptionException e) { System.err.println("????: " + e.getOption()); printUsage(PROGNAME); return false; } catch (ParseException e) { System.err.println(e.getMessage()); printUsage(PROGNAME); return false; } final String pkgName = commandLine.getOptionValue(PACKAGE_NAME.getOpt()); final String versionStr = commandLine.getOptionValue(OBB_VERSION.getOpt()); final Integer version = toInteger(versionStr); if (version == null) { System.err.println("??????: " + versionStr); printUsage(PROGNAME); return false; } final boolean isOverlay = commandLine.hasOption(OVERLAY_FLAG.getOpt()); final String saltStr = commandLine.getOptionValue(SALT.getOpt()); final byte[] salt; if (saltStr == null) { salt = null; } else { salt = toByteArray(saltStr, ObbInfoV1.SALT_LENGTH); if (salt == null) { System.err.println("????: " + saltStr); printUsage(PROGNAME); return false; } } final String[] nonRecognizedArgs = commandLine.getArgs(); if (nonRecognizedArgs.length == 0) { System.err.println("????????"); printUsage(PROGNAME); return false; } if (nonRecognizedArgs.length != 1) { System.err.println("???????"); printUsage(PROGNAME); return false; } final File targetFile = new File(nonRecognizedArgs[0]); final RandomAccessFile targetRaFile; try { targetRaFile = new RandomAccessFile(targetFile, "rw"); } catch (FileNotFoundException e) { System.err.println("????: " + targetFile.getPath()); return false; } try { try { final ObbInfoV1 info = ObbInfoV1.fromFile(targetRaFile); System.err.println( "?? OBB ???????: " + info.toString()); return false; } catch (IOException e) { System.err .println("????????: " + targetFile.getPath()); return false; } catch (NotObbException e) { // } int flag = 0; if (isOverlay) { flag |= ObbInfoV1.FLAG_OVERLAY; } if (salt != null) { flag |= ObbInfoV1.FLAG_SALTED; } final ObbInfoV1 obbInfo = new ObbInfoV1(flag, salt, pkgName, version.intValue()); final ByteBuffer obbInfoBytes = obbInfo.toBytes(); // ??? targetRaFile.setLength(targetRaFile.length() + obbInfoBytes.remaining()); targetRaFile.seek(targetRaFile.length() - obbInfoBytes.remaining()); targetRaFile.write(obbInfoBytes.array(), obbInfoBytes.arrayOffset(), obbInfoBytes.remaining()); } catch (IOException e) { System.err.println("OBB ?????????: " + targetFile.getPath()); return false; } finally { try { targetRaFile.close(); } catch (IOException e) { System.err.println("OBB ?????????: " + targetFile.getPath()); return false; } } System.err.println("OBB ??????????: " + targetFile.getPath()); return true; }
From source file:at.ac.tuwien.ims.latex2mobiformulaconv.app.Main.java
private static void parseCli(String[] args) { CommandLineParser parser = new PosixParser(); try {/* ww w .j a v a 2 s . c o m*/ CommandLine cmd = parser.parse(options, args); // Show usage, ignore other parameters and quit if (cmd.hasOption('h')) { usage(); logger.debug("Help called, main() exit."); System.exit(0); } if (cmd.hasOption('d')) { // Activate debug markup only - does not affect logging! debugMarkupOutput = true; } if (cmd.hasOption('m')) { exportMarkup = true; } if (cmd.hasOption('t')) { title = cmd.getOptionValue('t'); } if (cmd.hasOption('f')) { filename = cmd.getOptionValue('f'); } if (cmd.hasOption('n')) { exportMarkup = true; // implicit markup export noMobiConversion = true; } if (cmd.hasOption('i')) { String[] inputValues = cmd.getOptionValues('i'); for (String inputValue : inputValues) { inputPaths.add(Paths.get(inputValue)); } } else { logger.error("You have to specify an inputPath file or directory!"); usage(); System.exit(1); } if (cmd.hasOption('o')) { String outputDirectory = cmd.getOptionValue('o'); outputPath = Paths.get(outputDirectory).toAbsolutePath(); logger.debug("Output path: " + outputPath.toAbsolutePath().toString()); if (!Files.isDirectory(outputPath) && Files.isRegularFile(outputPath)) { logger.error("Given output directory is a file! Exiting..."); System.exit(1); } if (!Files.exists(outputPath)) { Files.createDirectory(outputPath); } if (!Files.isWritable(outputPath)) { logger.error("Given output directory is not writable! Exiting..."); logger.debug(outputPath.toAbsolutePath().toString()); System.exit(1); } logger.debug("Output path: " + outputPath.toAbsolutePath().toString()); } else { // Set default output directory if none is given outputPath = workingDirectory; } // If set, replace LaTeX Formulas with PNG images, created by if (cmd.hasOption("r")) { logger.debug("Picture Flag set"); replaceWithPictures = true; } if (cmd.hasOption("u")) { logger.debug("Use calibre instead of kindlegen"); useCalibreInsteadOfKindleGen = true; } // Executable configuration LatexToHtmlConverter latexToHtmlConverter = (LatexToHtmlConverter) applicationContext .getBean("latex2html-converter"); if (cmd.hasOption(latexToHtmlConverter.getExecOption().getOpt())) { String execValue = cmd.getOptionValue(latexToHtmlConverter.getExecOption().getOpt()); logger.info("LaTeX to HTML Executable argument was given: " + execValue); Path execPath = Paths.get(execValue); latexToHtmlConverter.setExecPath(execPath); } String htmlToMobiConverterBean = KINDLEGEN_HTML2MOBI_CONVERTER; if (useCalibreInsteadOfKindleGen) { htmlToMobiConverterBean = CALIBRE_HTML2MOBI_CONVERTER; } HtmlToMobiConverter htmlToMobiConverter = (HtmlToMobiConverter) applicationContext .getBean(htmlToMobiConverterBean); Option htmlToMobiOption = htmlToMobiConverter.getExecOption(); if (cmd.hasOption(htmlToMobiOption.getOpt())) { String execValue = cmd.getOptionValue(htmlToMobiOption.getOpt()); logger.info("HTML to Mobi Executable argument was given: " + execValue); try { Path execPath = Paths.get(execValue); htmlToMobiConverter.setExecPath(execPath); } catch (InvalidPathException e) { logger.error("Invalid path given for --" + htmlToMobiOption.getLongOpt() + " <" + htmlToMobiOption.getArgName() + ">"); logger.error("I will try to use your system's PATH variable..."); } } } catch (MissingOptionException m) { Iterator<String> missingOptionsIterator = m.getMissingOptions().iterator(); while (missingOptionsIterator.hasNext()) { logger.error("Missing required options: " + missingOptionsIterator.next() + "\n"); } usage(); System.exit(1); } catch (MissingArgumentException a) { logger.error("Missing required argument for option: " + a.getOption().getOpt() + "/" + a.getOption().getLongOpt() + "<" + a.getOption().getArgName() + ">"); usage(); System.exit(2); } catch (ParseException e) { logger.error("Error parsing command line arguments, exiting..."); logger.error(e.getMessage(), e); System.exit(3); } catch (IOException e) { logger.error("Error creating output path at " + outputPath.toAbsolutePath().toString()); logger.error(e.getMessage(), e); logger.error("Exiting..."); System.exit(4); } }
From source file:net.mindengine.galen.runner.GalenArguments.java
public static GalenArguments parse(String[] args) throws ParseException { args = processSystemProperties(args); //TODO Refactor this ugly way of handling command line arguments. It should be separate per action. Options options = new Options(); options.addOption("u", "url", true, "Url for test page"); options.addOption("j", "javascript", true, "Path to javascript file which will be executed after test page loads"); options.addOption("i", "include", true, "Tags for sections that should be included in test run"); options.addOption("e", "exclude", true, "Tags for sections that should be excluded from test run"); options.addOption("s", "size", true, "Browser screen size"); options.addOption("H", "htmlreport", true, "Path for html output report"); options.addOption("g", "testngreport", true, "Path for testng xml report"); options.addOption("r", "recursive", false, "Flag for recursive tests scan"); options.addOption("p", "parallel-suites", true, "Amount of suites to be run in parallel"); options.addOption("v", "version", false, "Current version"); CommandLineParser parser = new PosixParser(); CommandLine cmd = null;// www. j a va 2s .c o m try { cmd = parser.parse(options, args); } catch (MissingArgumentException e) { throw new IllegalArgumentException("Missing value for " + e.getOption().getLongOpt(), e); } GalenArguments galen = new GalenArguments(); galen.setOriginal(merge(args)); String[] leftovers = cmd.getArgs(); if (leftovers.length > 0) { String action = leftovers[0]; galen.setAction(action); if (leftovers.length > 1) { List<String> paths = new LinkedList<String>(); for (int i = 1; i < leftovers.length; i++) { paths.add(leftovers[i]); } galen.setPaths(paths); } } galen.setUrl(cmd.getOptionValue("u")); galen.setIncludedTags(convertTags(cmd.getOptionValue("i", ""))); galen.setExcludedTags(convertTags(cmd.getOptionValue("e", ""))); galen.setScreenSize(convertScreenSize(cmd.getOptionValue("s"))); galen.setJavascript(cmd.getOptionValue("javascript")); galen.setTestngReport(cmd.getOptionValue("g")); galen.setRecursive(cmd.hasOption("r")); galen.setHtmlReport(cmd.getOptionValue("H")); galen.setParallelSuites(Integer.parseInt(cmd.getOptionValue("p", "0"))); galen.setPrintVersion(cmd.hasOption("v")); verifyArguments(galen); return galen; }
From source file:calculadora.controlador.ControladorCLI.java
/** * Metodo realiza la segunda etapa de analisis del commons cli de Apache. * * Lee la linea de comandos y una vez la lee con exito pasa el comando a que * busque la funcion de ese comando./*from w w w . j a v a 2s. c o m*/ * * Si los argumentos recibidos son mayores de tres no conviene parsear, ya * que nunca deveria ser mayor de 3. * * Controlo aqui la excepcion para poder personalizarla y poder mostrar la * informacion correcta por pantalla con el comando equivocado. * * @see PosixParser POSIX * @see CommandLineParser * @see CommandLine * @exception MissingArgumentException error de argumentos de comandos * @exception UnrecognizedOptionException no reconoce el comando * @exception ParseException error al parsear los comandos * @param args Linea de comandos * @throws IllegalArgumentException error argumentos de java o programa * @throws NumberFormatException error de tipo de argumentos */ private void leerComando(String[] args) throws IllegalArgumentException, NumberFormatException { try { //Si hay mas de 3 argumentos directamente error, no conviene parsear if (args.length > 3) { notificarError( "Demasiados comandos o argumentos, solo se puede " + "realizar una operacion cada vez."); } else { CommandLineParser parser = new PosixParser(); CommandLine cmdLine = parser.parse(opciones, args); buscarComando(cmdLine); } } catch (MissingArgumentException mae) { //Si la opcion es de posix largo muestro el nombre del comando largo //Sino muestro el posix corto de error. notificarError(mae.getOption().hasLongOpt() ? "El comando '--" + mae.getOption().getLongOpt() + "' necesita mas argumentos." : "El comando '-" + mae.getOption().getOpt() + "' necesita mas argumentos."); } catch (UnrecognizedOptionException uoe) { notificarError("'" + uoe.getOption() + "' no se reconoce como " + "comando interno del programa."); } catch (ParseException pe) { notificarError(pe.getMessage()); } }
From source file:org.apache.tomcat.vault.VaultTool.java
public VaultTool(String[] args) { initOptions();/*from w ww.j a v a 2s .co m*/ parser = new PosixParser(); try { cmdLine = parser.parse(options, args, true); } catch (MissingArgumentException e) { Option opt = e.getOption(); for (String s : args) { String optionSpecified = s.replaceAll("^-+", ""); if (optionSpecified.equals(opt.getLongOpt()) || optionSpecified.equals(opt.getOpt())) { System.err.println("Missing argument for option: " + optionSpecified); System.exit(2); } } } catch (ParseException e) { System.err.println(e.getMessage()); System.exit(2); } }