List of usage examples for org.apache.commons.cli ParseException ParseException
public ParseException(String message)
ParseException
with the specified detail message. From source file:com.archivas.clienttools.arcmover.cli.ManagedCLIJob.java
protected void setUpExportListThread(CommandLine cmdLine) throws ParseException { List<ExportListType> exportTypeList = new ArrayList<ExportListType>(); String exportListPath = ""; String exportListPrefix = ""; if (cmdLine.hasOption(EXPORT_RESULTS_TYPE)) { String resultsListStr = cmdLine.getOptionValue(EXPORT_RESULTS_TYPE); if (resultsListStr.contains("ALL")) { for (ExportListType type : ExportListType.values()) { if (type == ExportListType.CONFLICT && !supportsConflictReports()) { continue; }/* w w w. j a va 2 s. co m*/ exportTypeList.add(type); } } else { String[] resultsList = resultsListStr.split(","); for (String type : resultsList) { try { ExportListType listType = ExportListType.valueOf(type.trim()); if (listType == ExportListType.CONFLICT && !supportsConflictReports()) { throw new IllegalArgumentException(); } exportTypeList.add(listType); } catch (IllegalArgumentException e) { throw new ParseException("Values provided for export-results does not match expected."); } } } } if (cmdLine.hasOption(EXPORT_RESULTS_PATH)) { exportListPath = cmdLine.getOptionValue(EXPORT_RESULTS_PATH); } if (cmdLine.hasOption(EXPORT_RESULTS_PREFIX)) { exportListPrefix = cmdLine.getOptionValue(EXPORT_RESULTS_PREFIX); } try { exportResults = new ExportResults(exportListPath, exportListPrefix, exportTypeList.contains(ExportListType.FAILURE), exportTypeList.contains(ExportListType.SUCCESS), exportTypeList.contains(ExportListType.JOBLIST), exportTypeList.contains(ExportListType.CONFLICT)); } catch (IOException e) { LOG.log(Level.WARNING, "IOException caught when trying to create export files. Make sure path is valid and writable", e); throw new ParseException( "IOException caught when trying to create export files. Make sure path is valid and writable"); } }
From source file:com.archivas.clienttools.arcmover.cli.ArcProfileMgr.java
public ProfileType validateProfileType(CommandLine cmdLine) throws ParseException { String option = "type"; if (!cmdLine.hasOption(option)) { throw new ParseException("Missing Option: " + option); }// www.jav a 2 s . c o m String value = cmdLine.getOptionValue(option); ProfileType retval = null; boolean validType = false; for (ProfileType type : ProfileType.values()) { if (type.toString().equals(value) && type != ProfileType.FILESYSTEM) { // Filesystem is // already // created validType = true; } } if (!validType) { throw new ParseException("Invalid Profile Type: " + value); } retval = ProfileType.valueOf(value); if (retval == null) { throw new ParseException("Invalid Profile Type: " + newProfileType); } return retval; }
From source file:lcmc.LCMC.java
/** Inits the application. */ protected static String initApp(final String[] args) { try {//from w w w . j a v a 2s. com /* Metal */ UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel"); MetalLookAndFeel.setCurrentTheme(new OceanTheme() { /** e.g. arrows on split pane... */ protected ColorUIResource getPrimary1() { return new ColorUIResource(ClusterBrowser.STATUS_BACKGROUND); } /** unknown to me */ protected ColorUIResource getPrimary2() { return new ColorUIResource(ClusterBrowser.PANEL_BACKGROUND); } /** unknown to me */ protected ColorUIResource getPrimary3() { return new ColorUIResource(ClusterBrowser.PANEL_BACKGROUND); } /** Button and other borders. */ protected ColorUIResource getSecondary1() { return new ColorUIResource(AppDefaults.BACKGROUND_DARK); } protected ColorUIResource getSecondary2() { return new ColorUIResource(ClusterBrowser.PANEL_BACKGROUND); } /** Split pane divider. Line in the main menu. */ protected ColorUIResource getSecondary3() { return new ColorUIResource(ClusterBrowser.PANEL_BACKGROUND); } }); } catch (final Exception e) { /* ignore it then */ } Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { public void uncaughtException(final Thread t, final Throwable ex) { Tools.appError("uncaught exception", ex.toString(), (Exception) ex); } }); float fps = 20.0f; final Options options = new Options(); options.addOption("h", HELP_OP, false, "print this help"); options.addOption(null, KEEP_HELPER_OP, false, "do not overwrite the lcmc-gui-helper program"); options.addOption(null, RO_OP, false, "read only mode"); options.addOption(null, OP_OP, false, "operator mode"); options.addOption(null, ADMIN_OP, false, "administrator mode"); options.addOption(null, OP_MODE_OP, true, "operating mode. <arg> can be:\n" + "ro - read only\n" + "op - operator\n" + "admin - administrator"); options.addOption(null, NOLRM_OP, false, "do not show removed resources from LRM."); options.addOption(null, "auto", true, "for testing"); options.addOption("v", VERSION_OP, false, "print version"); options.addOption(null, AUTO_OP, true, "for testing"); options.addOption(null, NO_UPGRADE_CHECK_OP, false, "disable upgrade check"); options.addOption(null, NO_PLUGIN_CHECK_OP, false, "disable plugin check, DEPRECATED: there are no plugins"); options.addOption(null, TIGHTVNC_OP, false, "enable tight vnc viewer"); options.addOption(null, ULTRAVNC_OP, false, "enable ultra vnc viewer"); options.addOption(null, REALVNC_OP, false, "enable real vnc viewer"); options.addOption(null, BIGDRBDCONF_OP, false, "create one big drbd.conf, instead of many" + " files in drbd.d/ directory"); options.addOption(null, STAGING_DRBD_OP, false, "enable more DRBD installation options"); options.addOption(null, STAGING_PACEMAKER_OP, false, "enable more Pacemaker installation options"); options.addOption(null, VNC_PORT_OFFSET_OP, true, "offset for port forwarding"); options.addOption(null, SLOW_OP, false, "specify this if you have slow computer"); options.addOption(null, RESTORE_MOUSE_OP, false, "for testing"); options.addOption(null, SCALE_OP, true, "scale fonts and sizes of elements in percent (100)"); options.addOption(null, ID_DSA_OP, true, "location of id_dsa file ($HOME/.ssh/id_dsa)"); options.addOption(null, ID_RSA_OP, true, "location of id_rsa file ($HOME/.ssh/id_rsa)"); options.addOption(null, KNOWN_HOSTS_OP, true, "location of known_hosts file ($HOME/.ssh/known_hosts)"); options.addOption(null, OUT_OP, true, "where to redirect the standard out"); options.addOption(null, DEBUG_OP, true, "debug level, 0 - none, 3 - all"); options.addOption("c", CLUSTER_OP, true, "define a cluster"); final Option hostOp = new Option("h", HOST_OP, true, "define a cluster, used with --cluster option"); hostOp.setArgs(10000); options.addOption(hostOp); options.addOption(null, SUDO_OP, false, "whether to use sudo, used with --cluster option"); options.addOption(null, USER_OP, true, "user to use with sudo, used with --cluster option"); options.addOption(null, PORT_OP, true, "ssh port, used with --cluster option"); options.addOption(null, ADVANCED_OP, false, "start in an advanced mode"); options.addOption(null, ONE_HOST_CLUSTER_OP, false, "allow one host cluster"); final CommandLineParser parser = new PosixParser(); String autoArgs = null; try { final CommandLine cmd = parser.parse(options, args); if (cmd.hasOption(OUT_OP)) { final String out = cmd.getOptionValue(OUT_OP); if (out != null) { try { System.setOut(new PrintStream(new FileOutputStream(out))); } catch (final FileNotFoundException e) { System.exit(2); } } } if (cmd.hasOption(DEBUG_OP)) { final String level = cmd.getOptionValue(DEBUG_OP); if (level != null && Tools.isNumber(level)) { Tools.setDebugLevel(Integer.parseInt(level)); } else { throw new ParseException("cannot parse debug level: " + level); } } boolean tightvnc = cmd.hasOption(TIGHTVNC_OP); boolean ultravnc = cmd.hasOption(ULTRAVNC_OP); final boolean realvnc = cmd.hasOption(REALVNC_OP); if (!tightvnc && !ultravnc && !realvnc) { if (Tools.isLinux()) { tightvnc = true; } else if (Tools.isWindows()) { ultravnc = true; } else { tightvnc = true; ultravnc = true; } } boolean advanced = cmd.hasOption(ADVANCED_OP); Tools.getConfigData().setAdvancedMode(advanced); Tools.getConfigData().setTightvnc(tightvnc); Tools.getConfigData().setUltravnc(ultravnc); Tools.getConfigData().setRealvnc(realvnc); Tools.getConfigData().setUpgradeCheckEnabled(!cmd.hasOption(NO_UPGRADE_CHECK_OP)); Tools.getConfigData().setBigDRBDConf(cmd.hasOption(BIGDRBDCONF_OP)); Tools.getConfigData().setStagingDrbd(cmd.hasOption(STAGING_DRBD_OP)); Tools.getConfigData().setStagingPacemaker(cmd.hasOption(STAGING_PACEMAKER_OP)); Tools.getConfigData().setNoLRM(cmd.hasOption(NOLRM_OP)); Tools.getConfigData().setKeepHelper(cmd.hasOption(KEEP_HELPER_OP)); Tools.getConfigData().setOneHostCluster(cmd.hasOption(ONE_HOST_CLUSTER_OP)); final String pwd = System.getProperty("user.home"); final String scaleOp = cmd.getOptionValue(SCALE_OP, "100"); try { final int scale = Integer.parseInt(scaleOp); Tools.getConfigData().setScale(scale); Tools.resizeFonts(scale); } catch (java.lang.NumberFormatException e) { Tools.appWarning("cannot parse scale: " + scaleOp); } final String idDsaPath = cmd.getOptionValue(ID_DSA_OP, pwd + "/.ssh/id_dsa"); final String idRsaPath = cmd.getOptionValue(ID_RSA_OP, pwd + "/.ssh/id_rsa"); final String knownHostsPath = cmd.getOptionValue(KNOWN_HOSTS_OP, pwd + "/.ssh/known_hosts"); Tools.getConfigData().setIdDSAPath(idDsaPath); Tools.getConfigData().setIdRSAPath(idRsaPath); Tools.getConfigData().setKnownHostPath(knownHostsPath); final String opMode = cmd.getOptionValue(OP_MODE_OP); autoArgs = cmd.getOptionValue(AUTO_OP); if (cmd.hasOption(HELP_OP)) { final HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("java -jar LCMC.jar [OPTIONS]", options); System.exit(0); } if (cmd.hasOption(VERSION_OP)) { System.out.println("LINUX CLUSTER MANAGEMENT CONSOLE " + Tools.getRelease() + " by Rasto Levrinc"); System.exit(0); } if (cmd.hasOption("ro") || "ro".equals(opMode)) { Tools.getConfigData().setAccessType(ConfigData.AccessType.RO); Tools.getConfigData().setMaxAccessType(ConfigData.AccessType.RO); } else if (cmd.hasOption("op") || "op".equals(opMode)) { Tools.getConfigData().setAccessType(ConfigData.AccessType.OP); Tools.getConfigData().setMaxAccessType(ConfigData.AccessType.OP); } else if (cmd.hasOption("admin") || "admin".equals(opMode)) { Tools.getConfigData().setAccessType(ConfigData.AccessType.ADMIN); Tools.getConfigData().setMaxAccessType(ConfigData.AccessType.ADMIN); } else if (opMode != null) { Tools.appWarning("unknown operating mode: " + opMode); } if (cmd.hasOption(SLOW_OP)) { fps = fps / 2; } if (cmd.hasOption(RESTORE_MOUSE_OP)) { /* restore mouse if it is stuck in pressed state, during * robot tests. */ RoboTest.restoreMouse(); } final String vncPortOffsetString = cmd.getOptionValue(VNC_PORT_OFFSET_OP); if (vncPortOffsetString != null && Tools.isNumber(vncPortOffsetString)) { Tools.getConfigData().setVncPortOffset(Integer.parseInt(vncPortOffsetString)); } Tools.getConfigData().setAnimFPS(fps); if (cmd.hasOption(CLUSTER_OP) || cmd.hasOption(HOST_OP)) { parseClusterOptions(cmd); } } catch (ParseException exp) { System.out.println("ERROR: " + exp.getMessage()); System.exit(1); } Tools.debug(null, "max mem: " + Runtime.getRuntime().maxMemory() / 1024 / 1024 + "m", 1); return autoArgs; }
From source file:TmlCommandLine.java
@SuppressWarnings("rawtypes") private static void operation() throws ParseException { if (line.hasOption("ocorpus") && (line.getOptionValue("ocorpus") == null || line.getOptionValue("ocorpus").trim().length() == 0)) { throw new ParseException("Invalid ocorpus option argument value."); }//from w ww . j av a2 s .co m String allDocsCorpusType = line.getOptionValue("oalldocs"); if (line.hasOption("oalldocs") && !allDocsCorpusType.equals("sentence") && !allDocsCorpusType.equals("paragraph")) { throw new ParseException("Invalid oalldocs option argument value."); } String[] operations = line.getOptionValues("operations"); if (operations == null || operations.length == 0) { throw new ParseException("You must specify at least one operation!"); } if (!startTML()) { throw new ParseException("Fatal error initializing TML."); } try { repository = new Repository(repositoryFolder); } catch (Exception e) { logger.error(e); return; } String[] corpusQueries = null; if (line.hasOption("ocorpus")) { corpusQueries = new String[1]; corpusQueries[0] = line.getOptionValue("ocorpus"); } else if (line.hasOption("oalldocs")) { List<TextDocument> docs = null; try { docs = repository.getAllTextDocuments(); } catch (Exception e) { logger.fatal("Couldn't get list of documents from repository."); throw new ParseException(e.getMessage()); } corpusQueries = new String[docs.size()]; for (int i = 0; i < docs.size(); i++) { TextDocument doc = docs.get(i); String referenceId = null; if (line.getOptionValue("oalldocs").equals("sentence")) referenceId = "p*d" + doc.getExternalId(); else referenceId = doc.getExternalId(); corpusQueries[i] = "type:" + line.getOptionValue("oalldocs") + " AND reference:" + referenceId; } } String corpusLine = "NoCorpus"; if (line.hasOption("ocorpus")) corpusLine = line.getOptionValue("ocorpus").replaceAll("\\W", ""); else if (line.hasOption("oalldocs")) corpusLine = "AllDocuments"; String resultsFilename = repository.getIndexPath().substring(1).replaceAll("[/\\\\]", "_") + "." + corpusLine + "." + (new SimpleDateFormat("yyyy-MM-dd-hh-mm")).format(new Date()) + ".txt"; // Initialize arrays and set default parameters DimensionalityReduction[] dims = new DimensionalityReduction[1]; double[] dimths = new double[1]; boolean lanczos = false; TermSelection[] tsels = new TermSelection[1]; double[] tselths = new double[1]; LocalWeight[] twlocals = new LocalWeight[1]; GlobalWeight[] twglobals = new GlobalWeight[1]; CorpusParameters parameters = new CorpusParameters(); dims[0] = parameters.getDimensionalityReduction(); dimths[0] = parameters.getDimensionalityReductionThreshold(); lanczos = parameters.isLanczosSVD(); tsels[0] = parameters.getTermSelectionCriterion(); tselths[0] = parameters.getTermSelectionThreshold(); twlocals[0] = parameters.getTermWeightLocal(); twglobals[0] = parameters.getTermWeightGlobal(); // If the ocpar option is given, load the parameters file and // override the default parameters if (line.hasOption("ocpar")) { parameters.loadFromFile(new File(line.getOptionValue("ocpar"))); dims[0] = parameters.getDimensionalityReduction(); dimths[0] = parameters.getDimensionalityReductionThreshold(); lanczos = parameters.isLanczosSVD(); tsels[0] = parameters.getTermSelectionCriterion(); tselths[0] = parameters.getTermSelectionThreshold(); twlocals[0] = parameters.getTermWeightLocal(); twglobals[0] = parameters.getTermWeightGlobal(); } else { // Check for every possible parameter if (line.hasOption("odim")) { dims = new DimensionalityReduction[line.getOptionValues("odim").length]; for (int i = 0; i < dims.length; i++) dims[i] = DimensionalityReduction.valueOf(line.getOptionValues("odim")[i]); } if (line.hasOption("odimth")) { dimths = new double[line.getOptionValues("odimth").length]; for (int i = 0; i < dimths.length; i++) dimths[i] = Double.parseDouble(line.getOptionValues("odimth")[i]); } if (line.hasOption("olanczos")) lanczos = true; else lanczos = false; if (line.hasOption("otsel")) { tsels = new TermSelection[line.getOptionValues("otsel").length]; for (int i = 0; i < tsels.length; i++) tsels[i] = TermSelection.valueOf(line.getOptionValues("otsel")[i]); } if (line.hasOption("otselth")) { tselths = new double[line.getOptionValues("otselth").length]; for (int i = 0; i < tselths.length; i++) tselths[i] = Double.parseDouble(line.getOptionValues("otselth")[i]); } if (line.hasOption("otwl")) { twlocals = new LocalWeight[line.getOptionValues("otwl").length]; for (int i = 0; i < twlocals.length; i++) twlocals[i] = LocalWeight.valueOf(line.getOptionValues("otwl")[i]); } if (line.hasOption("otwg")) { twglobals = new GlobalWeight[line.getOptionValues("otwg").length]; for (int i = 0; i < twglobals.length; i++) twglobals[i] = GlobalWeight.valueOf(line.getOptionValues("otwg")[i]); } } String resultsFolder = line.getOptionValue("oresults"); FileWriter writer = null; if (resultsFolder != null) { File resultsFold = new File(resultsFolder); if (resultsFold.exists() && resultsFold.isDirectory()) { try { File results = new File(resultsFolder + "/" + resultsFilename); writer = new FileWriter(results); } catch (IOException e) { logger.error(e); writer = null; } } } // Create the whole combination of parameters for (TermSelection tsel : tsels) for (double tselth : tselths) for (LocalWeight lw : twlocals) for (GlobalWeight gw : twglobals) { CorpusParameters p = new CorpusParameters(); p.setTermSelectionCriterion(tsel); p.setLanczosSVD(lanczos); p.setTermSelectionCriterion(tsel); p.setTermSelectionThreshold(tselth); p.setTermWeightLocal(lw); p.setTermWeightGlobal(gw); logger.debug("Parameters to execute: " + p.toString()); SearchResultsCorpus backgroundKnowledgeCorpus = null; // If we have background knowledge, load it if (line.hasOption("obk")) { backgroundKnowledgeCorpus = new SearchResultsCorpus(line.getOptionValue("obk")); if (line.hasOption("obkpar")) { CorpusParameters bkParameters = new CorpusParameters(); bkParameters.loadFromFile(new File(line.getOptionValue("obkpar"))); backgroundKnowledgeCorpus.setParameters(bkParameters); } try { backgroundKnowledgeCorpus.load(repository); } catch (Exception e) { logger.error("Couldn't load background knowledge corpus."); logger.error(e); e.printStackTrace(); continue; } } // Create the corpus with the query for (String corpusQuery : corpusQueries) { SearchResultsCorpus corpus = new SearchResultsCorpus(corpusQuery); // Loading the corpus try { corpus.setParameters(p); corpus.load(repository); } catch (Exception e) { logger.error("Couldn't load corpus. " + corpus.getLuceneQuery()); logger.error(e); continue; } for (DimensionalityReduction dred : dims) for (double dimth : dimths) { p.setDimensionalityReduction(dred); p.setDimensionalityReductionThreshold(dimth); try { corpus.getParameters().setDimensionalityReduction(dred); corpus.getParameters().setDimensionalityReductionThreshold(dimth); if (backgroundKnowledgeCorpus == null) corpus.getSemanticSpace().calculate(); } catch (Exception e) { logger.error("Couldn't calculate corpus' semantic space"); logger.error(e); e.printStackTrace(); continue; } for (String operation : operations) { Class classDefinition = null; Operation op = null; try { classDefinition = Class .forName("tml.vectorspace.operations." + operation); op = (Operation) classDefinition.newInstance(); } catch (Exception e) { logger.error("The operation wasn't found"); e.printStackTrace(); logger.error(e); continue; } op.setCorpus(corpus); if (backgroundKnowledgeCorpus != null) op.setBackgroundKnowledgeCorpus(backgroundKnowledgeCorpus); try { op.start(); } catch (Exception e) { logger.error("Error while performing the operation"); e.printStackTrace(); logger.error(e); continue; } String backgroundline = "None"; String parametersline = corpus.getParameters().toString(); if (backgroundKnowledgeCorpus != null) { backgroundline = backgroundKnowledgeCorpus.getLuceneQuery() + " [" + backgroundKnowledgeCorpus.getSemanticSpace() .getDimensionsKept() + "]"; parametersline = backgroundKnowledgeCorpus.getParameters().toString(); } else { backgroundline += " [" + corpus.getSemanticSpace().getDimensionsKept() + "]"; } String corpusline = "Corpus:" + corpus.getLuceneQuery() + "\n" + "Operation:" + op.getClass().getName() + "\n" + "Background:" + backgroundline + "\n" + "Parameters:" + parametersline + "\n"; if (writer != null) { try { writer.append(corpusline); writer.append(op.getResultsCSVString()); } catch (IOException e) { logger.error("Error writing file " + corpusline); logger.error(e); } } else { System.out.println(corpusline); System.out.println(op.getResultsCSVString()); } } } } } if (writer != null) { try { writer.close(); } catch (IOException e) { logger.error(e); } } }
From source file:com.symbian.utils.config.ConfigUtils.java
/** * @param aKey/*www .java 2 s .c o m*/ * @return <code>true</code> if the preference for the Key is * <code>true</code>, <code>false</code> otherwise. * @throws ParseException */ public boolean isPreference(final int aKey) throws ParseException { String aKeyLiteal = iPreferenceLiterals[aKey]; Object[] lConfigMap = (Object[]) iConfigMap.get(aKeyLiteal); if (lConfigMap == null) { throw new NullPointerException("Incorrect key: " + aKeyLiteal); } if (!Boolean.class.equals(lConfigMap[2])) { throw new ParseException("This preference " + aKeyLiteal + " cannot use the setPreference() method. It must be of type " + lConfigMap[2].toString()); } LOGGER.finest("Getting Preference " + aKey + ": " + iSavedConfig.get(aKeyLiteal)); return ((Boolean) ((CheckGetConfig) lConfigMap[0]).get(aKeyLiteal, iSavedConfig.get(aKeyLiteal))) .booleanValue(); }
From source file:com.github.houbie.lesscss.LesscCommandLineParser.java
private void setResourceReader(CommandLine cmd) throws ParseException { if (cmd.hasOption(INCLUDE_PATH_OPTION)) { String[] paths = cmd.getOptionValue(INCLUDE_PATH_OPTION).split("[:|;]"); File[] files = new File[paths.length]; for (int i = 0; i < paths.length; i++) { files[i] = new File(paths[i]); }//w ww .j a v a 2 s .c om resourceReader = new FileSystemResourceReader(encoding, files); } else { File source = new File(sourceLocation); if (!source.exists()) { throw new ParseException( sourceLocation + " can not be found. Check the location or use --" + INCLUDE_PATH_OPTION); } resourceReader = new FileSystemResourceReader(encoding, source.getAbsoluteFile().getParentFile()); } }
From source file:bdsup2sub.cli.CommandLineParser.java
private void parseCropLinesOption(CommandLine line) throws ParseException { if (line.hasOption(CROP_LINES)) { String value = line.getOptionValue(CROP_LINES); cropLines = Optional.of(ToolBox.getInt(value.trim())); if (cropLines.get() < 0) { throw new ParseException("Invalid crop lines value: " + value); }//from ww w .jav a2 s. c o m } }
From source file:de.clusteval.serverclient.BackendClient.java
/** * A helper method for {@link #main(String[])} to parse the command line * parameters and put them into a wrapper object. * // w ww . ja v a2s . c om * @param params * The input command line parameters. * @param stopAtNonOptions * A boolean indicating, whether to throw an exception on unknown * options. * @return A wrapper object containing the parsed and valid parameters. * @throws ParseException */ private static CommandLine parseParams(String[] params, boolean stopAtNonOptions) throws ParseException { CommandLineParser parser = new PosixParser(); CommandLine cmd = parser.parse(clientCLIOptions, params, stopAtNonOptions); Level logLevel; if (cmd.hasOption("logLevel")) { switch (Integer.parseInt(cmd.getOptionValue("logLevel"))) { case 0: logLevel = Level.ALL; break; case 1: logLevel = Level.TRACE; break; case 2: logLevel = Level.DEBUG; break; case 3: logLevel = Level.INFO; break; case 4: logLevel = Level.WARN; break; case 5: logLevel = Level.ERROR; break; case 6: logLevel = Level.OFF; break; default: throw new ParseException("The logLevel argument requires one of the value of [0,1,2,3,4,5,6]"); } } else { logLevel = Level.INFO; } ((ch.qos.logback.classic.Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME)).setLevel(logLevel); return cmd; }
From source file:lcmc.ArgumentParser.java
public void parseClusterOptionsAndCreateClusterButton(final CommandLine cmd) throws ParseException { String clusterName = null;/*from w w w . j av a2 s. c o m*/ List<HostOptions> hostsOptions = null; final Map<String, List<HostOptions>> clusters = new LinkedHashMap<String, List<HostOptions>>(); for (final Option option : cmd.getOptions()) { final String op = option.getLongOpt(); if (CLUSTER_OP.equals(op)) { clusterName = option.getValue(); if (clusterName == null) { throw new ParseException("could not parse " + CLUSTER_OP + " option"); } clusters.put(clusterName, new ArrayList<HostOptions>()); } else if (HOST_OP.equals(op)) { final String[] hostNames = option.getValues(); if (clusterName == null) { clusterName = "default"; clusters.put(clusterName, new ArrayList<HostOptions>()); } if (hostNames == null) { throw new ParseException("could not parse " + HOST_OP + " option"); } hostsOptions = new ArrayList<HostOptions>(); for (final String hostNameEntered : hostNames) { final String hostName; String port = null; if (hostNameEntered.indexOf(':') > 0) { final String[] he = hostNameEntered.split(":"); hostName = he[0]; port = he[1]; if (port != null && port.isEmpty() || !lcmc.common.domain.util.Tools.isNumber(port)) { throw new ParseException("could not parse " + HOST_OP + " option"); } } else { hostName = hostNameEntered; } final HostOptions ho = new HostOptions(hostName); if (port != null) { ho.setPort(port); } hostsOptions.add(ho); clusters.get(clusterName).add(ho); } } else if (SUDO_OP.equals(op)) { if (hostsOptions == null) { throw new ParseException(SUDO_OP + " must be defined after " + HOST_OP); } for (final HostOptions ho : hostsOptions) { ho.setUseSudo(true); } } else if (USER_OP.equals(op)) { if (hostsOptions == null) { throw new ParseException(USER_OP + " must be defined after " + HOST_OP); } final String userName = option.getValue(); if (userName == null) { throw new ParseException("could not parse " + USER_OP + " option"); } for (final HostOptions ho : hostsOptions) { ho.setLoginUser(userName); } } else if (PORT_OP.equals(op)) { if (hostsOptions == null) { throw new ParseException(PORT_OP + " must be defined after " + HOST_OP); } final String port = option.getValue(); if (port == null) { throw new ParseException("could not parse " + PORT_OP + " option"); } for (final HostOptions ho : hostsOptions) { ho.setPort(port); } } else if (PCMKTEST_OP.equals(op)) { final String index = option.getValue(); if (index != null && !index.isEmpty()) { application.setAutoTest(new Test(StartTests.Type.PCMK, index.charAt(0))); } } else if (DRBDTEST_OP.equals(op)) { final String index = option.getValue(); if (index != null && !index.isEmpty()) { application.setAutoTest(new Test(StartTests.Type.DRBD, index.charAt(0))); } } else if (VMTEST_OP.equals(op)) { final String index = option.getValue(); if (index != null && !index.isEmpty()) { application.setAutoTest(new Test(StartTests.Type.VM, index.charAt(0))); } } else if (GUITEST_OP.equals(op)) { final String index = option.getValue(); if (index != null && !index.isEmpty()) { application.setAutoTest(new Test(StartTests.Type.GUI, index.charAt(0))); } } } for (final Map.Entry<String, List<HostOptions>> clusterEntry : clusters.entrySet()) { final List<HostOptions> hostOptions = clusterEntry.getValue(); if (hostOptions.size() < 1 || (hostOptions.size() == 1 && !application.isOneHostCluster())) { throw new ParseException("not enough hosts for cluster: " + clusterEntry.getKey()); } } final String failedHost = setUserConfigFromOptions(clusters); if (failedHost != null) { LOG.appWarning("parseClusterOptions: could not resolve host \"" + failedHost + "\" skipping"); } }
From source file:bdsup2sub.cli.CommandLineParser.java
private void parseAlphaCropThresholdOption(CommandLine line) throws ParseException { if (line.hasOption(ALPHA_CROP_THRESHOLD)) { String value = line.getOptionValue(ALPHA_CROP_THRESHOLD); alphaCropThreshold = Optional.of(ToolBox.getInt(value.trim())); if (alphaCropThreshold.get() < 0 || alphaCropThreshold.get() > 255) { throw new ParseException("Illegal number range for alpha cropping threshold: " + value); }// ww w. ja v a2 s.c o m } }