Example usage for org.apache.commons.cli CommandLine getOptionValues

List of usage examples for org.apache.commons.cli CommandLine getOptionValues

Introduction

In this page you can find the example usage for org.apache.commons.cli CommandLine getOptionValues.

Prototype

public String[] getOptionValues(char opt) 

Source Link

Document

Retrieves the array of values, if any, of an option.

Usage

From source file:net.lldp.checksims.ChecksimsCommandLine.java

/**
 * Parse basic CLI flags and produce a ChecksimsConfig.
 *
 * @param cli Parsed command line/*from w ww.  j  a  v  a2 s.c o  m*/
 * @return Config derived from parsed CLI
 * @throws ChecksimsException Thrown on invalid user input or internal error
 */
static ChecksimsConfig parseBaseFlags(CommandLine cli) throws ChecksimsException {
    checkNotNull(cli);

    // If we don't have a logger, set one up
    if (logs == null) {
        logs = LoggerFactory.getLogger(ChecksimsCommandLine.class);
    }

    // Create a base config to work from
    ChecksimsConfig config = new ChecksimsConfig();

    // Parse plagiarism detection algorithm
    if (cli.hasOption("a")) {
        config = config.setAlgorithm(
                AlgorithmRegistry.getInstance().getImplementationInstance(cli.getOptionValue("a")));
        config = config.setTokenization(config.getAlgorithm().getPercentableCalculator());
    }

    // Parse tokenization
    if (cli.hasOption("t")) {
        config = config.setTokenization(SubmissionPercentableCalculator.fromString(cli.getOptionValue("t")));
    }

    // Parse number of threads to use
    if (cli.hasOption("j")) {
        int numThreads = Integer.parseInt(cli.getOptionValue("j"));

        if (numThreads < 1) {
            throw new ChecksimsException("Thread count must be positive!");
        }

        config = config.setNumThreads(numThreads);
    }

    if (cli.hasOption("ignoreInvalid")) {
        config = config.ignoreInvalid();
    }

    // Parse preprocessors
    // Ensure no duplicates
    if (cli.hasOption("p")) {
        List<SubmissionPreprocessor> preprocessors = SetUniqueList.setUniqueList(new ArrayList<>());

        String[] preprocessorsToUse = cli.getOptionValues("p");
        for (String s : preprocessorsToUse) {
            SubmissionPreprocessor p = PreprocessorRegistry.getInstance().getImplementationInstance(s);
            preprocessors.add(p);
        }
        config = config.setPreprocessors(preprocessors);
    }

    // Parse output strategies
    // Ensure no duplicates
    if (cli.hasOption("o")) {
        String[] desiredStrategies = cli.getOptionValues("o");
        Set<String> deduplicatedStrategies = new HashSet<>(Arrays.asList(desiredStrategies));

        if (deduplicatedStrategies.isEmpty()) {
            throw new ChecksimsException("Error: did not obtain a valid output strategy!");
        }

        // Convert to MatrixPrinters
        Set<MatrixPrinter> printers = new HashSet<>();
        for (String name : deduplicatedStrategies) {
            printers.add(MatrixPrinterRegistry.getInstance().getImplementationInstance(name));
        }

        config = config.setOutputPrinters(printers);
    }

    return config;
}

From source file:com.github.horrorho.liquiddonkey.settings.commandline.CommandLinePropertiesFactory.java

public Properties from(Properties parent, CommandLineOptions commandLineOptions, String[] args)
        throws ParseException {

    Properties properties = new Properties(parent);
    CommandLineParser parser = new DefaultParser();
    Options options = commandLineOptions.options();
    CommandLine cmd = parser.parse(options, args);

    switch (cmd.getArgList().size()) {
    case 0:/*from   w ww .j  ava  2s .c om*/
        // No authentication credentials
        break;
    case 1:
        // Authentication token
        properties.put(Property.AUTHENTICATION_TOKEN.name(), cmd.getArgList().get(0));
        break;
    case 2:
        // AppleId/ password pair
        properties.put(Property.AUTHENTICATION_APPLEID.name(), cmd.getArgList().get(0));
        properties.put(Property.AUTHENTICATION_PASSWORD.name(), cmd.getArgList().get(1));
        break;
    default:
        throw new ParseException(
                "Too many non-optional arguments, expected appleid/ password or authentication token only.");
    }

    Iterator<Option> it = cmd.iterator();

    while (it.hasNext()) {
        Option option = it.next();
        String opt = commandLineOptions.opt(option);
        String property = commandLineOptions.property(option).name();

        if (option.hasArgs()) {
            // String array
            properties.put(property, joined(cmd.getOptionValues(opt)));
        } else if (option.hasArg()) {
            // String value
            properties.put(property, cmd.getOptionValue(opt));
        } else {
            // String boolean
            properties.put(property, Boolean.toString(cmd.hasOption(opt)));
        }
    }
    return properties;
}

From source file:edu.usc.scrc.PriorityPruner.CommandLineOptions.java

/**
 * Checks that options with one argument are entered correct number of times
 * (1 time for options currently using this method) by counting
 * corresponding arguments. If more than the specified number of arguments
 * are provided in the command line an exception will get thrown.
 * //www  .j  a va2  s  . co m
 * @param numArgs
 *            allowed number of times the option should be entered
 * @param option
 *            name of the option
 * @param commandLine
 *            CommandLine-object, which holds the command line arguments
 * @throws PriorityPrunerException
 *             if too many arguments were provided to the command line
 */
private void checkInput(int numArgs, String option, CommandLine commandLine) throws PriorityPrunerException {
    String[] args = commandLine.getOptionValues(option);
    if (args.length > numArgs) {
        throw new PriorityPrunerException(
                "Option '" + option + "' specified more than once. Type --help for help.");
    }
}

From source file:in.hatimi.nosh.support.CmdLineManager.java

private boolean injectField(CommandLine cmdLine, Object target, Field field) {
    CmdLineOption clo = field.getAnnotation(CmdLineOption.class);
    if (clo == null) {
        return true;
    }//from w ww .j a v  a2  s .  c  o m

    String nameToUse = clo.name();
    if (StringUtils.isBlank(nameToUse)) {
        nameToUse = clo.longName();
    }

    if (clo.argCount() == 0) {
        if (cmdLine.hasOption(nameToUse)) {
            return injectBoolean(target, field, true);
        } else {
            return injectBoolean(target, field, false);
        }
    }
    if (clo.argCount() == 1) {
        String value = cmdLine.getOptionValue(nameToUse);
        if (value != null) {
            return injectString(target, field, value);
        }
    } else if (clo.valueSeparator() > 0) {
        Properties props = cmdLine.getOptionProperties(nameToUse);
        if (props != null) {
            return injectProperties(target, field, props);
        }
    } else if (clo.argCount() > 1) {
        String[] values = cmdLine.getOptionValues(nameToUse);
        if (values != null && values.length > 0) {
            return injectStringArray(target, field, values);
        }
    }
    return true;
}

From source file:com.netspective.commons.xml.ParseContext.java

public boolean prepareTransformInstruction(String instructionParams) {
    CommandLine cmd = null;
    try {/*from ww w  .  j av  a 2  s.c  o  m*/
        cmd = CLPARSER.parse(TRANSFORM_OPTIONS, StringUtils.split(instructionParams));
    } catch (ParseException e) {
        errors.add("Unable to process transformation command <?" + TRANSFORM_INSTRUCTION + " "
                + instructionParams + "?>: " + e.toString());
        return false;
    }

    if (!cmd.hasOption('s')) {
        errors.add("No style-sheet options specified for <?" + TRANSFORM_INSTRUCTION + " " + instructionParams
                + "?> PI.");
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(TRANSFORM_INSTRUCTION, TRANSFORM_OPTIONS);
        return false;
    }

    boolean isResource = cmd.hasOption("r");
    List sources = new ArrayList();
    String[] styleSheets = cmd.getOptionValues('s');
    for (int i = 0; i < styleSheets.length; i++) {
        if (isResource) {
            InputStream stream = getClass().getClassLoader().getResourceAsStream(styleSheets[i].trim());
            if (stream == null)
                errors.add("Error in <?" + TRANSFORM_INSTRUCTION + " " + instructionParams + "?>, stylesheet '"
                        + styleSheets[i].trim() + "' not found as a resource in ClassLoader "
                        + getClass().getClassLoader());
            else {
                sources.add(new StreamSource(stream));
            }
        } else {
            File sourceFile = resolveFile(styleSheets[i].trim());
            try {
                if (inputSrcTracker != null) {
                    FileTracker preProcessor = new FileTracker();
                    preProcessor.setFile(sourceFile);
                    inputSrcTracker.addPreProcessor(preProcessor);
                }
                sources.add(new StreamSource(new FileInputStream(sourceFile)));
            } catch (FileNotFoundException e) {
                errors.add("Error in <?" + TRANSFORM_INSTRUCTION + " " + instructionParams + "?>, stylesheet '"
                        + sourceFile.getAbsolutePath() + "': " + e.toString());
                continue;
            }
        }
    }

    if (sources.size() == 0)
        return false;

    transformSources = (Source[]) sources.toArray(new Source[sources.size()]);
    return true;
}

From source file:co.turnus.analysis.buffers.MpcBoundedSchedulingCliLauncher.java

private static Configuration parseCommandLine(CommandLine cmd) throws ParseException {
    Configuration config = new BaseConfiguration();

    StringBuffer s = new StringBuffer();

    config.setProperty(VERBOSE, cmd.hasOption("v"));

    if (!cmd.hasOption("t")) {
        s.append("Trace project directory not specified. ");
    } else {/*from  www.  ja v a  2s . co  m*/
        String fileName = cmd.getOptionValue("t", "");
        File file = new File(fileName);
        if (file == null || !file.exists()) {
            s.append("Trace project does not exists. ");
        } else {
            config.setProperty(TRACE_PROJECT, fileName);
        }
    }

    if (!cmd.hasOption("o")) {
        s.append("Output directory not specified. ");
    } else {
        String fileName = cmd.getOptionValue("o", "");
        File file = new File(fileName);
        if (file == null || !file.exists()) {
            s.append("Output directory does not exists. ");
        } else {
            config.setProperty(OUTPUT_PATH, fileName);
        }
    }

    if (cmd.hasOption("xls")) {
        String fileName = cmd.getOptionValue("xls", "");
        if (fileName == null || fileName.isEmpty()) {
            s.append("XLS file name is not correct. ");
        } else {
            config.setProperty(XLS, fileName);
        }
    }

    if (cmd.hasOption("bxdf")) {
        String fileName = cmd.getOptionValue("bxdf", "");
        if (fileName == null || fileName.isEmpty()) {
            s.append("BXDF file name is not correct. ");
        } else {
            config.setProperty(BXDF, fileName);
        }
    }

    if (!cmd.hasOption("s") && !cmd.hasOption("d")) {
        s.append("please choose at least one option for the trace cut (max steps or max degree) ");
    }

    if (cmd.hasOption("s")) {
        String[] sArray = cmd.getOptionValues("s");
        if (sArray.length == 1) {
            int value = Integer.parseInt(sArray[0]);
            config.addProperty(TRACE_CUT_STEPS_MIN, value);
            config.addProperty(TRACE_CUT_STEPS_MAX, value);
            config.addProperty(TRACE_CUT_STEPS_NUM, 1);
        } else if (sArray.length == 2) {
            int min = Integer.parseInt(sArray[0]);
            int max = Integer.parseInt(sArray[1]);
            config.addProperty(TRACE_CUT_STEPS_MIN, min);
            config.addProperty(TRACE_CUT_STEPS_MAX, max);
            config.addProperty(TRACE_CUT_STEPS_NUM, max - min + 1);
        } else {
            int min = Integer.parseInt(sArray[0]);
            int points = Integer.parseInt(sArray[1]);
            int max = Integer.parseInt(sArray[2]);
            config.addProperty(TRACE_CUT_STEPS_MIN, min);
            config.addProperty(TRACE_CUT_STEPS_NUM, points);
            config.addProperty(TRACE_CUT_STEPS_MAX, max);
        }
    }

    if (cmd.hasOption("d")) {
        String[] sArray = cmd.getOptionValues("d");
        if (sArray.length == 1) {
            int value = Integer.parseInt(sArray[0]);
            config.addProperty(TRACE_CUT_DEGREE_MIN, value);
            config.addProperty(TRACE_CUT_DEGREE_MAX, value);
            config.addProperty(TRACE_CUT_DEGREE_NUM, 1);
        } else if (sArray.length == 2) {
            int min = Integer.parseInt(sArray[0]);
            int max = Integer.parseInt(sArray[1]);
            config.addProperty(TRACE_CUT_DEGREE_MIN, min);
            config.addProperty(TRACE_CUT_DEGREE_MAX, max);
            config.addProperty(TRACE_CUT_DEGREE_NUM, max - min + 1);
        } else {
            int min = Integer.parseInt(sArray[0]);
            int points = Integer.parseInt(sArray[1]);
            int max = Integer.parseInt(sArray[2]);
            config.addProperty(TRACE_CUT_DEGREE_MIN, min);
            config.addProperty(TRACE_CUT_DEGREE_NUM, points);
            config.addProperty(TRACE_CUT_DEGREE_MAX, max);
        }
    }

    if (cmd.hasOption("c")) {
        String[] sArray = cmd.getOptionValues("c");
        if (sArray.length == 1) {
            int value = Integer.parseInt(sArray[0]);
            config.addProperty(HC_MIN, value);
            config.addProperty(HC_MAX, value);
            config.addProperty(HC_NUM, 1);
        } else if (sArray.length == 2) {
            int min = Integer.parseInt(sArray[0]);
            int max = Integer.parseInt(sArray[1]);
            config.addProperty(HC_MIN, min);
            config.addProperty(HC_MAX, max);
            config.addProperty(HC_NUM, max - min + 1);
        } else {
            int min = Integer.parseInt(sArray[0]);
            int points = Integer.parseInt(sArray[1]);
            int max = Integer.parseInt(sArray[2]);
            config.addProperty(HC_MIN, min);
            config.addProperty(HC_NUM, points);
            config.addProperty(HC_MAX, max);
        }
    } else {
        s.append("the control horizon has not been choosed");
    }

    boolean recovery = cmd.hasOption("r");
    config.setProperty(RECOVERY, recovery);

    boolean bitAccurate = cmd.hasOption("b");
    config.setProperty(BIT_ACCURATE, bitAccurate);

    boolean zeroStartingPoint = cmd.hasOption("z");
    config.setProperty(ZERO_STARTING_POINT, zeroStartingPoint);

    boolean quickCut = cmd.hasOption("q");
    config.setProperty(QUICK_CUT, quickCut);

    String error = s.toString();
    if (!error.isEmpty()) {
        throw new ParseException(error);
    }

    return config;
}

From source file:com.jagornet.dhcpv6.server.DhcpV6Server.java

/**
 * Parses the command line options./*  www. j  a  v  a2 s . c  o  m*/
 * 
 * @param args the command line argument array
 * 
 * @return true, if all arguments were successfully parsed
 */
protected boolean parseOptions(String[] args) {
    try {
        CommandLine cmd = parser.parse(options, args);
        if (cmd.hasOption("?")) {
            return false;
        }
        if (cmd.hasOption("c")) {
            configFilename = cmd.getOptionValue("c");
        }
        if (cmd.hasOption("p")) {
            String p = cmd.getOptionValue("p");
            try {
                portNumber = Integer.parseInt(p);
            } catch (NumberFormatException ex) {
                portNumber = DhcpConstants.SERVER_PORT;
                System.err.println(
                        "Invalid port number: '" + p + "' using default: " + portNumber + " Exception=" + ex);
            }
        }
        if (cmd.hasOption("m")) {
            String[] ifnames = cmd.getOptionValues("m");
            if ((ifnames == null) || (ifnames.length < 1)) {
                ifnames = new String[] { "*" };
            }
            mcastNetIfs = getIPv6NetIfs(ifnames);
            if ((mcastNetIfs == null) || mcastNetIfs.isEmpty()) {
                return false;
            }
        }
        if (cmd.hasOption("u")) {
            String[] addrs = cmd.getOptionValues("u");
            if ((addrs == null) || (addrs.length < 1)) {
                addrs = new String[] { "*" };
            }
            ucastAddrs = getIpAddrs(addrs);
            if ((ucastAddrs == null) || ucastAddrs.isEmpty()) {
                return false;
            }
        }
        if (cmd.hasOption("v")) {
            System.err.println(Version.getVersion());
            System.exit(0);
        }
    } catch (ParseException pe) {
        System.err.println("Command line option parsing failure: " + pe);
        return false;
    } catch (SocketException se) {
        System.err.println("Network interface socket failure: " + se);
        return false;
    } catch (UnknownHostException he) {
        System.err.println("IP Address failure: " + he);
    }

    return true;
}

From source file:co.turnus.analysis.profiler.orcc.dynamic.OrccDynamicProfilerOptions.java

public static Configuration getConfiguration(CommandLine cli) {
    try {// w  w w .ja va  2s.co m
        Configuration conf = new BaseConfiguration();
        conf.setProperty(VERBOSE, cli.hasOption("v"));

        conf.setProperty(SIMULATOR_NAME, NAME);

        String stmp = cli.getOptionValue("p", "");
        conf.setProperty(ORCC_PROJECT, stmp);

        stmp = cli.getOptionValue("x", "");
        conf.setProperty(ORCC_XDF, stmp);

        Boolean btmp = cli.hasOption("i");
        if (btmp) {
            stmp = cli.getOptionValue("i", "");
            conf.setProperty(ORCC_SOURCE_USE, !stmp.isEmpty());
            conf.setProperty(ORCC_SOURCE_FILE, stmp);
        } else {
            conf.setProperty(ORCC_SOURCE_USE, false);
            conf.setProperty(ORCC_SOURCE_FILE, "");
        }

        btmp = cli.hasOption("t");
        if (btmp) {
            stmp = cli.getOptionValue("t", "");
            conf.setProperty(CREATE_TRACE_PROJECT, !stmp.isEmpty());
            conf.setProperty(TRACE_PROJECT_NAME, stmp);
        } else {
            conf.setProperty(CREATE_TRACE_PROJECT, false);
            conf.setProperty(TRACE_PROJECT_NAME, "");
        }

        btmp = cli.hasOption("stack-protector");
        conf.setProperty(STACK_PROTECTION, btmp);

        btmp = cli.hasOption("z");
        conf.setProperty(TRACE_COMPRESS, btmp);

        btmp = cli.hasOption("prof");
        conf.setProperty(EXPORT_PROFILING, btmp);

        stmp = cli.getOptionValue("versioner", GitVersioner.NAME);
        conf.setProperty(VERSIONER, stmp);

        stmp = cli.getOptionValue("scheduler", RoundRobinScheduler.NAME);
        conf.setProperty(ORCC_SCHEDULER, stmp);

        boolean resize[] = { false, false, false };
        if (cli.hasOption("resizer")) {
            String[] buff = cli.getOptionValues("resizer");
            for (int i = 0; i < resize.length; i++) {
                resize[i] = Boolean.parseBoolean(buff[i]);
            }
        }

        conf.setProperty(TYPE_RESIZE_NATIVEPORTS, resize[0]);
        conf.setProperty(TYPE_RESIZE_TO32BITS, resize[1]);
        conf.setProperty(TYPE_RESIZE_TONBITS, resize[2]);

        boolean transfo[] = { false, false, false, false, false, false };
        if (cli.hasOption("transfo")) {
            String[] buff = cli.getOptionValues("transfo");
            for (int i = 0; i < transfo.length; i++) {
                transfo[i] = Boolean.parseBoolean(buff[i]);
            }
        }
        conf.setProperty(TRANSFO_CONSTANTFOLDING, transfo[0]);
        conf.setProperty(TRANSFO_CONSTANTPROPAGATION, transfo[1]);
        conf.setProperty(TRANSFO_DEADACTIONS, transfo[2]);
        conf.setProperty(TRANSFO_EXPREVAL, transfo[3]);
        conf.setProperty(TRANSFO_DEADCODE, transfo[4]);
        conf.setProperty(TRANSFO_VARINIT, transfo[5]);

        int itmp = Integer.parseInt(cli.getOptionValue("b", "512"));
        conf.setProperty(FIFO_DEFAULT, itmp);

        // set the output path
        stmp = cli.getOptionValue("o", "");
        setOutputPath(conf, stmp);

        // set the gantt chart options
        btmp = cli.hasOption("gantt");
        conf.setProperty(EXPORT_GANTT, btmp);
        if (btmp) {
            stmp = conf.getString(OUTPUT_PATH);
            stmp = new File(stmp, "ganttChart." + TurnusExtension.VCD).getAbsolutePath();
            conf.setProperty(VCD_FILE, stmp);
        }

        return conf;

    } catch (Exception e) {
        throw new TurnusRuntimeException("Error parsing the launch configuration options", e);
    }
}

From source file:de.haber.xmind2latex.cli.CliParameters.java

/**
 * Creates a {@link XMindToLatexExporter} for the given arguments.
 * /*from www .j  av  a 2  s  . c om*/
 * @param args Arguments to configure this {@link XMindToLatexExporter}.
 * 
 * @return A created {@link XMindToLatexExporter} or null, if no {@link CliParameters#INPUT} parameter is used.
 * 
 * @throws ParseException, NumberFormatException for invalid arguments
 * @throws ConfigurationException for invalid input files
 * @throws IllegalArgumentException if the given input file does not exist
 */
public static XMindToLatexExporter build(String[] args) throws ParseException {
    CommandLineParser parser = new BasicParser();
    CommandLine cmd = parser.parse(options, args, false);

    if (cmd.getOptions().length == 0) {
        throw new ParseException("Parameter -" + INPUT + " expected.");
    }

    if (cmd.hasOption(VERSION)) {
        printVersion();
    }

    CliParameters.validateNumberOfArguments(cmd, INPUT, options);
    if (cmd.hasOption(INPUT)) {
        File in = new File(cmd.getOptionValue(INPUT));
        Builder builder = new Builder(in);
        if (cmd.hasOption(FORCE)) {
            CliParameters.validateNumberOfArguments(cmd, FORCE, options);
            builder.overwritesExistingFiles(true);
        }

        File out;
        if (cmd.hasOption(OUTPUT)) {
            CliParameters.validateNumberOfArguments(cmd, OUTPUT, options);
            out = new File(cmd.getOptionValue(OUTPUT));
            builder.withTargetFile(out);
        }

        if (cmd.hasOption(TEMPLATE_LEVEL)) {
            CliParameters.validateNumberOfArguments(cmd, TEMPLATE_LEVEL, options);

            String level = cmd.getOptionValue(TEMPLATE_LEVEL);
            try {
                int levelAsInt = Integer.parseInt(level);
                if (levelAsInt < 0) {
                    throw new NumberFormatException();
                }
                builder.withMaxLevel(levelAsInt);
            } catch (NumberFormatException e) {
                ParseException ex = new ParseException(
                        "The level argument of option " + TEMPLATE_LEVEL + " has to be a positive integer.");
                ex.addSuppressed(e);
                throw ex;
            }

        }
        if (cmd.hasOption(HELP)) {
            CliParameters.validateNumberOfArguments(cmd, HELP, options);

            showHelp();
        }

        if (cmd.hasOption(ENVIRONMENT)) {
            CliParameters.validateNumberOfArguments(cmd, ENVIRONMENT, options);

            String[] env = cmd.getOptionValues(ENVIRONMENT);
            for (int i = 0; i + 2 < env.length; i = i + 3) {
                String level = env[i];
                String start = env[i + 1];
                String end = env[i + 2];
                try {
                    int levelAsInt = Integer.parseInt(level);
                    builder.withEnvironmentTemplates(levelAsInt, start, end);
                } catch (NumberFormatException e) {
                    ParseException ex = new ParseException(
                            "The level argument of option " + ENVIRONMENT + " has to be an integer.");
                    ex.addSuppressed(e);
                    throw ex;
                }
            }
        }
        if (cmd.hasOption(LEVEL)) {
            CliParameters.validateNumberOfArguments(cmd, LEVEL, options);

            String[] tmp = cmd.getOptionValues(LEVEL);

            for (int i = 0; i + 1 < tmp.length; i = i + 2) {
                String level = tmp[i];
                String template = tmp[i + 1];
                try {
                    int levelAsInt = Integer.parseInt(level);
                    builder.withTemplate(levelAsInt, template);
                } catch (NumberFormatException e) {
                    ParseException ex = new ParseException(
                            "The level argument of option " + LEVEL + " has to be an integer.");
                    ex.addSuppressed(e);
                    throw ex;
                }
            }
        }
        return builder.build();
    } else {
        return null;
    }
}

From source file:co.turnus.analysis.buffers.BoundedBufferSchedulingCliLauncher.java

private static Configuration parseCommandLine(CommandLine cmd) throws ParseException {
    Configuration config = new BaseConfiguration();

    StringBuffer s = new StringBuffer();

    config.setProperty(VERBOSE, cmd.hasOption("v"));

    if (!cmd.hasOption("t")) {
        s.append("Trace project directory not specified. ");
    } else {/*  w  w w.  j a va 2s.c om*/
        String fileName = cmd.getOptionValue("t", "");
        File file = new File(fileName);
        if (file == null || !file.exists()) {
            s.append("Trace project does not exists. ");
        } else {
            config.setProperty(TRACE_PROJECT, fileName);
        }
    }

    if (!cmd.hasOption("o")) {
        s.append("Output directory not specified. ");
    } else {
        String fileName = cmd.getOptionValue("o", "");
        File file = new File(fileName);
        if (file == null || !file.exists()) {
            s.append("Output directory does not exists. ");
        } else {
            config.setProperty(OUTPUT_PATH, fileName);
        }
    }

    if (cmd.hasOption("xls")) {
        String fileName = cmd.getOptionValue("xls", "");
        if (fileName == null || fileName.isEmpty()) {
            s.append("XLS file name is not correct. ");
        } else {
            config.setProperty(XLS, fileName);
        }
    }

    if (cmd.hasOption("bxdf")) {
        String fileName = cmd.getOptionValue("bxdf", "");
        if (fileName == null || fileName.isEmpty()) {
            s.append("BXDF file name is not correct. ");
        } else {
            config.setProperty(BXDF, fileName);
        }
    }

    boolean bitAccurate = cmd.hasOption("b");
    config.setProperty(BIT_ACCURATE, bitAccurate);

    boolean zeroStartingPoint = cmd.hasOption("z");
    config.setProperty(ZERO_STARTING_POINT, zeroStartingPoint);

    boolean quickCut = cmd.hasOption("q");
    config.setProperty(QUICK_CUT, quickCut);

    if (cmd.hasOption("s")) {
        String[] sArray = cmd.getOptionValues("s");
        if (sArray.length == 1) {
            int value = Integer.parseInt(sArray[0]);
            config.addProperty(TRACE_CUT_STEPS_MIN, value);
            config.addProperty(TRACE_CUT_STEPS_MAX, value);
            config.addProperty(TRACE_CUT_STEPS_NUM, 1);
        } else if (sArray.length == 2) {
            int min = Integer.parseInt(sArray[0]);
            int max = Integer.parseInt(sArray[1]);
            config.addProperty(TRACE_CUT_STEPS_MIN, min);
            config.addProperty(TRACE_CUT_STEPS_MAX, max);
            config.addProperty(TRACE_CUT_STEPS_NUM, max - min + 1);
        } else {
            int min = Integer.parseInt(sArray[0]);
            int points = Integer.parseInt(sArray[1]);
            int max = Integer.parseInt(sArray[2]);
            config.addProperty(TRACE_CUT_STEPS_MIN, min);
            config.addProperty(TRACE_CUT_STEPS_NUM, points);
            config.addProperty(TRACE_CUT_STEPS_MAX, max);
        }
    }

    String error = s.toString();
    if (!error.isEmpty()) {
        throw new ParseException(error);
    }

    return config;
}