List of usage examples for org.apache.commons.cli ParseException ParseException
public ParseException(String message)
ParseException
with the specified detail message. From source file:iDynoOptimizer.MOEAFramework26.src.org.moeaframework.analysis.tools.Solve.java
/** * Parses the decision variable specification either from the * {@code --lowerBounds} and {@code --upperBounds} options or the * {@code --variables} option./*from w w w . j a v a2 s . c o m*/ * * @param commandLine the command line arguments * @return the parsed variable specifications * @throws ParseException if an error occurred while parsing the variable * specifications */ private List<Variable> parseVariables(CommandLine commandLine) throws ParseException { List<Variable> variables = new ArrayList<Variable>(); if (commandLine.hasOption("lowerBounds") && commandLine.hasOption("upperBounds")) { String[] lowerBoundTokens = commandLine.getOptionValue("lowerBounds").split(","); String[] upperBoundTokens = commandLine.getOptionValue("upperBounds").split(","); if (lowerBoundTokens.length != upperBoundTokens.length) { throw new ParseException("lower bound and upper bounds not " + "the same length"); } for (int i = 0; i < lowerBoundTokens.length; i++) { double lowerBound = Double.parseDouble(lowerBoundTokens[i]); double upperBound = Double.parseDouble(upperBoundTokens[i]); variables.add(EncodingUtils.newReal(lowerBound, upperBound)); } } else if (commandLine.hasOption("variables")) { String[] tokens = commandLine.getOptionValue("variables").split(","); for (String token : tokens) { variables.add(parseVariableSpecification(token.trim().toUpperCase())); } } else { throw new ParseException( "must specify either the problem, the " + "variables, or the lower and upper bounds arguments"); } return variables; }
From source file:com.archivas.clienttools.arcmover.cli.ArcDelete.java
protected void parseArgs() throws ParseException { // create the command cmdLine parser CommandLineParser parser = new PosixParser(); CommandLine cmdLine;/*from w w w.j a v a 2s .c o m*/ // parse the command cmdLine arguments cmdLine = parser.parse(getOptions(), getArgs()); // Help printHelp = cmdLine.hasOption("h"); if (printHelp) { return; } initializeProfiles(cmdLine.hasOption("insecure")); @SuppressWarnings({ "unchecked" }) List<String> argList = cmdLine.getArgList(); // Handle the load schedule and export lists LoadSchedule schedule = LoadSchedule.getDefaultLoadSchedule(); getLoadSchedule(cmdLine, schedule); setUpExportListThread(cmdLine); // Check for debug setting where we can rerun a job -- this is for testing purposes only // Validate the input file if one was provided // See if we are rerunning, set up the job if we are boolean rerunning = handleRerunAndResume(cmdLine, schedule); if (rerunning) { List<String> extraOptions = new ArrayList<String>(); if (cmdLine.hasOption(PROFILE_OPTION)) { extraOptions.add(PROFILE_OPTION); } if (cmdLine.hasOption(PATH_OPTION)) { extraOptions.add(PATH_OPTION); } if (cmdLine.hasOption(OPERATION_OPTION)) { extraOptions.add(OPERATION_OPTION); } if (cmdLine.hasOption(REASON_OPTION)) { extraOptions.add(REASON_OPTION); } if (cmdLine.hasOption(JOB_NAME)) { extraOptions.add(JOB_NAME); } if (!extraOptions.isEmpty()) { throw new ParseException("The following supplied options are not allowed with --" + RESUME + " or --" + RERUN + ": " + extraOptions); } // The list_file is not allowed for rerun/resume if (argList.size() > numCmdLineArgs - 1) { throw new ParseException( "The list_file argument is not allowed with --" + RESUME + " or --" + RERUN); } } else { if (argList.size() != numCmdLineArgs) { throw new ParseException("Missing argument list_file."); } // Get the name of the input file String listFileName = argList.get(numCmdLineArgs - 1); // Required fields String srcProfileName = getProfileNameFromCmdLineAndValidateExistance(cmdLine, PROFILE_OPTION); AbstractProfileBase srcProfile = ProfileManager.getProfileByName(srcProfileName); // Optional fields String sourcePath = null; if (cmdLine.hasOption(PATH_OPTION)) { sourcePath = cmdLine.getOptionValue(PATH_OPTION); srcProfile.setDisplayPath(sourcePath); } String jobName = null; if (cmdLine.hasOption(JOB_NAME)) { jobName = cmdLine.getOptionValue(JOB_NAME); } DeleteJob.Operation operation = DeleteJob.Operation.DELETE; String reason = null; if (srcProfile instanceof Hcp3AuthNamespaceProfile) { if (cmdLine.hasOption(OPERATION_OPTION)) { String operationStr = cmdLine.getOptionValue(OPERATION_OPTION); try { operation = DeleteJob.Operation.getFromString(operationStr); } catch (IllegalArgumentException e) { throw new ParseException(e.getMessage()); } } // Make sure if the operation if a privileged on that we get a reason if (operation.isPrivilegedOperation()) { if (!cmdLine.hasOption(REASON_OPTION)) { throw new ParseException("The " + REASON_OPTION + " option is required with a " + operation.getStringRepresentation() + " operation."); } reason = cmdLine.getOptionValue(REASON_OPTION); } else { if (cmdLine.hasOption(REASON_OPTION)) { throw new ParseException("The " + REASON_OPTION + " option is only supported for " + DeleteJob.Operation.PRIVILEGED_DELETE.getStringRepresentation() + " and " + DeleteJob.Operation.PRIVILEGED_PURGE.getStringRepresentation() + " operations."); } } } else { List<String> extraOptions = new ArrayList<String>(); if (cmdLine.hasOption(OPERATION_OPTION)) { extraOptions.add(OPERATION_OPTION); } if (cmdLine.hasOption(REASON_OPTION)) { extraOptions.add(REASON_OPTION); } if (!extraOptions.isEmpty()) { throw new ParseException( "The following supplied options are only supported for HCP namespaces: " + extraOptions); } } // Validate the input file try { FileListParser.validateFile(new File(listFileName), srcProfile, sourcePath, ""); } catch (IOException e) { throw new ParseException("Error parsing input file. Msg: " + e.getMessage()); } catch (FileListParserException e) { throw new ParseException("Error parsing input file. Msg: " + e.getMessage()); } // Setup the job with the arguments try { setupDeleteJob(listFileName, srcProfile, sourcePath, jobName, operation, reason, schedule); managedJobImpl = arcMover.createManagedJob(managedJob); } catch (IllegalArgumentException e) { throw new ParseException( "IllegalArgumentException writing to database during file list parsing. Msg: " + e.getMessage()); } catch (DatabaseException e) { throw new ParseException( "DatabaseException writing to database during file list parsing. Msg: " + e.getMessage()); } catch (JobException e) { throw new ParseException( "JobException writing to database during file list parsing. Msg: " + e.getMessage()); } } }
From source file:bdsup2sub.cli.CommandLineParser.java
private void parseTargetFramerateOption(CommandLine line) throws ParseException { if (line.hasOption(TARGET_FRAMERATE)) { synchronizeFpsMode = true;//from ww w .j a v a 2s .c o m String value = line.getOptionValue(TARGET_FRAMERATE); if (value.equalsIgnoreCase("keep")) { // keep undefined } else { targetFrameRate = Optional.of(SubtitleUtils.getFps(value)); if (targetFrameRate.get() <= 0) { throw new ParseException("Invalid target framerate: " + value); } } } }
From source file:com.aliyun.odps.ship.upload.BlockUploader.java
private void checkDiscardBadData() throws ParseException, IOException { badRecords++;/*from www. ja v a 2 s . co m*/ if (badRecords > maxBadRecords) { DshipContext.INSTANCE.put(Constants.STATUS, SessionStatus.failed.toString()); sessionHistory.saveContext(); throw new ParseException(Constants.ERROR_INDICATOR + "bad records exceed " + maxBadRecords); } }
From source file:com.cloudera.csd.tools.MetricDescriptorGeneratorTool.java
private MapConfiguration generateAndValidateConfig(CommandLine cmdLine) throws ParseException { Preconditions.checkNotNull(cmdLine); MapConfiguration ret = new MapConfiguration(Maps.<String, Object>newHashMap()); for (Option option : cmdLine.getOptions()) { ret.addProperty(option.getLongOpt(), option.getValue()); }/*from w w w . j a v a 2 s.c o m*/ if (null == ret.getProperty(OPT_INPUT_MDL.getLongOpt())) { throw new ParseException("MetricGeneratorTool missing mdl file " + "location"); } else { String fileName = ret.getString(OPT_INPUT_MDL.getLongOpt()); File file = new File(fileName); if (!file.exists()) { throw new ParseException("MDL file '" + fileName + "' does not " + "exist"); } else if (!file.isFile()) { throw new ParseException("MDL file '" + fileName + "' is not a " + "file"); } } if (null == ret.getProperty(OPT_INPUT_FIXTURE.getLongOpt())) { throw new ParseException("MetricGeneratorTool missing fixture file " + "location"); } else { String fileName = ret.getString(OPT_INPUT_FIXTURE.getLongOpt()); File file = new File(fileName); if (!file.exists()) { throw new ParseException("Fixture file '" + fileName + "' does not " + "exist"); } else if (!file.isFile()) { throw new ParseException("Fixture file '" + fileName + "' is not a " + "file"); } } if (null != ret.getProperty(OPT_INPUT_CONVENTIONS.getLongOpt())) { String fileName = ret.getString(OPT_INPUT_CONVENTIONS.getLongOpt()); File file = new File(fileName); if (!file.exists()) { throw new ParseException("Conventions file '" + fileName + "' does " + "not exist"); } else if (!file.isFile()) { throw new ParseException("Conventions file '" + fileName + "' is " + "not a file"); } } if (null == ret.getProperty(OPT_ADAPTER_CLASS.getLongOpt())) { throw new ParseException("MetricGeneratorTool missing adapter class"); } else { String className = ret.getString(OPT_ADAPTER_CLASS.getLongOpt()); try { Class<?> adapterClass = this.getClass().getClassLoader().loadClass(className); if (!MetricFixtureAdapter.class.isAssignableFrom(adapterClass)) { throw new ParseException("Adapter class " + className + "is of the " + "wrong type"); } ret.addProperty(ADAPTER_CLASS_CONFIG, adapterClass); } catch (ClassNotFoundException e) { throw new ParseException("Unknown metric adapter " + className); } } return ret; }
From source file:com.zimbra.cs.index.LuceneViewer.java
public static void main(String args[]) throws Exception { CLI cli = new CLI(); CommandLine cl = cli.getCommandLine(args); if (!cl.hasOption(CLI.O_ACTION)) { cli.usage(new ParseException("missing required option " + CLI.O_ACTION), true); }//ww w .ja v a2 s . c o m String action = cl.getOptionValue(CLI.O_ACTION); if ("dump".equals(action)) { doDump(cl); } else if ("check".equals(action)) { doCheck(cl); } else { cli.usage(new ParseException("invalid option " + action), true); } }
From source file:eu.interedition.collatex.tools.CollationPipe.java
private static PrintWriter argumentToOutput(String arg, Charset outputCharset) throws ParseException, IOException { if ("-".equals(arg)) { return new PrintWriter(new OutputStreamWriter(System.out, outputCharset)); }/*from w ww. j a v a 2s .c o m*/ final File outFile = new File(arg); try { return new PrintWriter(Files.newBufferedWriter(outFile.toPath(), outputCharset)); } catch (FileNotFoundException e) { throw new ParseException("Output file '" + outFile + "' not found"); } }
From source file:de.pixida.logtest.buildserver.RunIntegrationTests.java
private void loadDefaultParameters(final CommandLine params) throws ParseException { File defaultParameterFile = null; try {/* w ww.jav a2s. c om*/ if (params.hasOption(DEFAULT_PARAMETER_FILE_SWITCH)) { defaultParameterFile = new File(params.getOptionValue(DEFAULT_PARAMETER_FILE_SWITCH)); final JSONObject root = new JSONObject( IOUtils.toString(defaultParameterFile.toURI(), StandardCharsets.UTF_8)); for (final String k : root.keySet()) { final String v = root.getString(k); this.defaultParameters.put(k, v); } LOG.debug("Loaded '{}' default parameters from file '{}'", this.defaultParameters.size(), defaultParameterFile.getCanonicalPath()); LOG.trace("Using default parameters: {}", this.defaultParameters); } else { LOG.debug("No default parameters set."); } } catch (final JSONException jsonEx) { throw new ParseException( "Failed to parse default parameter JSON data from file: " + jsonEx.getMessage()); } catch (final IOException e) { throw new ParseException("Failed to read default parameter file '" + defaultParameterFile.getAbsolutePath() + "': " + e.getMessage()); } }
From source file:com.cloudera.sqoop.tool.SqoopTool.java
/** * Configures a SqoopOptions according to the specified arguments. * Reads a set of arguments and uses them to configure a SqoopOptions * and its embedded configuration (i.e., through GenericOptionsParser.) * Stores any unparsed arguments in the extraArguments field. * * @param args the arguments to parse./*from w ww.j a va2 s . c o m*/ * @param conf if non-null, set as the configuration for the returned * SqoopOptions. * @param in a (perhaps partially-configured) SqoopOptions. If null, * then a new SqoopOptions will be used. If this has a null configuration * and conf is null, then a new Configuration will be inserted in this. * @param useGenericOptions if true, will also parse generic Hadoop * options into the Configuration. * @return a SqoopOptions that is fully configured by a given tool. */ public SqoopOptions parseArguments(String[] args, Configuration conf, SqoopOptions in, boolean useGenericOptions) throws ParseException, SqoopOptions.InvalidOptionsException { SqoopOptions out = in; if (null == out) { out = new SqoopOptions(); } if (null != conf) { // User specified a configuration; use it and override any conf // that may have been in the SqoopOptions. out.setConf(conf); } else if (null == out.getConf()) { // User did not specify a configuration, but neither did the // SqoopOptions. Fabricate a new one. out.setConf(new Configuration()); } String[] toolArgs = args; // args after generic parser is done. if (useGenericOptions) { try { toolArgs = ConfigurationHelper.parseGenericOptions(out.getConf(), args); } catch (IOException ioe) { ParseException pe = new ParseException("Could not parse generic arguments"); pe.initCause(ioe); throw pe; } } // Parse tool-specific arguments. ToolOptions toolOptions = new ToolOptions(); configureOptions(toolOptions); CommandLineParser parser = new SqoopParser(); CommandLine cmdLine = parser.parse(toolOptions.merge(), toolArgs, true); applyOptions(cmdLine, out); this.extraArguments = cmdLine.getArgs(); return out; }
From source file:bdsup2sub.cli.CommandLineParser.java
private void parseConvertFramerateOption(CommandLine line) throws ParseException { if (line.hasOption(CONVERT_FRAMERATE)) { convertFpsMode = true;/*w w w. ja v a2 s . c o m*/ if (line.getOptionValues(CONVERT_FRAMERATE).length != 2) { throw new ParseException("2 arguments needed for framerate conversion."); } String value = line.getOptionValues(CONVERT_FRAMERATE)[0]; if (value.equalsIgnoreCase("auto")) { // keep undefined } else { sourceFrameRate = Optional.of(SubtitleUtils.getFps(value)); if (sourceFrameRate.get() <= 0) { throw new ParseException("Invalid source framerate: " + value); } } value = line.getOptionValues(CONVERT_FRAMERATE)[1]; targetFrameRate = Optional.of(SubtitleUtils.getFps(value)); if (targetFrameRate.get() <= 0) { throw new ParseException("Invalid target framerate: " + value); } } }