Example usage for org.apache.commons.cli Option equals

List of usage examples for org.apache.commons.cli Option equals

Introduction

In this page you can find the example usage for org.apache.commons.cli Option equals.

Prototype

public boolean equals(Object o) 

Source Link

Usage

From source file:com.cjmcgraw.markupvalidator.args.Arguments.java

public static Arguments fromOption(Option option) {
    for (Arguments arg : Arguments.values()) {
        if (option.equals(arg.asOption()))
            return arg;
    }/*w  w  w . ja  va  2s . c  om*/
    return null;
}

From source file:com.netflix.cc.cli.CmdLineParametersParser.java

/**
 * Parses cmd line arguments./*from w  ww .  j  a  va2  s  . com*/
 *
 * @param args arguments from a command line
 * @return a command line parameter object or null if help was invoked.
 */
public CmdLineParameters parseCmdOptions(String[] args) throws ParseException {
    // create the parser
    CommandLineParser parser = new DefaultParser();
    CommandLine line = parser.parse(options, args);

    // --help
    if (line.hasOption(help.getLongOpt())) {
        // automatically generate the help statement
        HelpFormatter formatter = new HelpFormatter();
        formatter.setWidth(120);
        formatter.printHelp("ttml-to-stl", options);
        return null;
    }

    CmdLineParameters result = new CmdLineParameters();
    // --ttml parameters
    for (Option option : line.getOptions()) {
        if (option.equals(ttmlFile)) {
            TtmlInDescriptor ttmlInDescriptor = new TtmlInDescriptor();
            try {
                ttmlInDescriptor.setFile(option.getValue(0));
                ttmlInDescriptor.setOffsetMS(parseTtmlParameter(option, 1, "offsetMS"));
                ttmlInDescriptor.setStartMS(parseTtmlParameter(option, 2, "startMS"));
                ttmlInDescriptor.setEndMS(parseTtmlParameter(option, 3, "endMS"));
            } catch (IndexOutOfBoundsException e) {
                //It is error only if don't have file name
                //For required file it may not be thrown. We will check it later.
            }

            if (ttmlInDescriptor.getFile() == null) {
                throw new ParseException("--ttml parameter must have at least <file> attribute defined.");
            }

            result.getTtmlInDescriptors().add(ttmlInDescriptor);
        }
    }
    if (result.getTtmlInDescriptors().isEmpty()) {
        throw new ParseException("At least one input TTML file must be provided");
    }

    // TTML mode parameters
    boolean doOutputTTML = line.hasOption(outputTtml.getLongOpt());
    if (doOutputTTML) {
        result.setDoOuputTtml(true);
        result.setOutputTtmlFile(line.getOptionValue(outputTtml.getLongOpt()));
    }

    // SCC mode parameters
    boolean doOutputScc = line.hasOption(outputScc.getLongOpt());
    if (doOutputScc) {
        result.setDoOutputScc(true);
        result.setOutputSccFile(line.getOptionValue(outputScc.getLongOpt()));
    }

    return result;
}

From source file:com.netflix.imfutility.ttmltostl.inputparameters.CmdLineParametersParser.java

/**
 * Parses cmd line arguments./*from   www.jav  a2s. c  o m*/
 *
 * @param args arguments from a command line
 * @return a command line parameter object or null if help was invoked.
 */
public CmdLineParameters parseCmdOptions(String[] args) throws ParseException {
    // create the parser
    CommandLineParser parser = new DefaultParser();
    CommandLine line = parser.parse(options, args);

    // --help
    if (line.hasOption(help.getLongOpt())) {
        // automatically generate the help statement
        HelpFormatter formatter = new HelpFormatter();
        formatter.setWidth(120);
        formatter.printHelp("ttml-to-stl", options);
        return null;
    }

    CmdLineParameters result = new CmdLineParameters();
    // --ttml parameters
    for (Option option : line.getOptions()) {
        if (option.equals(ttmlFile)) {
            TtmlInDescriptor ttmlInDescriptor = new TtmlInDescriptor();
            try {
                ttmlInDescriptor.setFile(option.getValue(0));
                ttmlInDescriptor.setOffsetMS(parseTtmlParameter(option, 1, "offsetMS"));
                ttmlInDescriptor.setStartMS(parseTtmlParameter(option, 2, "startMS"));
                ttmlInDescriptor.setEndMS(parseTtmlParameter(option, 3, "endMS"));
            } catch (IndexOutOfBoundsException e) {
                //It is error only if don't have file name
                //For required file it may not be thrown. We will check it later.
            }

            if (ttmlInDescriptor.getFile() == null) {
                throw new ParseException("--ttml parameter must have at least <file> attribute defined.");
            }

            result.getTtmlInDescriptors().add(ttmlInDescriptor);
        }
    }
    if (result.getTtmlInDescriptors().size() == 0) {
        throw new ParseException("At least one input TTML file must be provided");
    }

    // TTML mode parameters
    boolean doOutputTTML = line.hasOption(outputTTML.getLongOpt());
    if (doOutputTTML) {
        result.setDoOuputTTML(true);
        result.setOutputTTMLFile(line.getOptionValue(outputTTML.getLongOpt()));
    }

    // STL mode parameters
    boolean doOutputSTL = line.hasOption(outputSTL.getLongOpt());
    if (doOutputSTL) {
        result.setDoOutputSTL(true);
        result.setOutputSTLFile(line.getOptionValue(outputSTL.getLongOpt()));
        if (!line.hasOption(metadataOpt.getLongOpt())) {
            throw new ParseException("A metadata.xml must be specified for STL mode");
        }
        String metadataXml = line.getOptionValue(metadataOpt.getLongOpt());
        if (!new File(metadataXml).isFile()) {
            throw new ParseException("A metadata.xml must be an existing file.");
        }
        result.setMetadataXml(metadataXml);
    }

    return result;
}

From source file:org.rhq.server.metrics.migrator.DataMigratorRunner.java

/**
 * Load the configuration options from file and overlay them on top of the default
 * options./*from  w w w.j  a v  a  2 s. com*/
 *
 * @param file config file
 */
private void loadConfigFile(String file) {
    try {
        File configFile = new File(file);
        if (!configFile.exists()) {
            throw new FileNotFoundException("Configuration file not found!");
        }

        Properties configProperties = new Properties();
        FileInputStream stream = new FileInputStream(configFile);
        configProperties.load(stream);
        stream.close();

        for (Object optionObject : options.getOptions()) {
            Option option = (Option) optionObject;
            Object optionValue;

            if ((optionValue = configProperties.get(option.getLongOpt())) != null) {
                log.debug("Configuration option loaded: " + option.getLongOpt() + " (" + option.getType()
                        + ") -> " + optionValue);

                if (option.equals(cassandraHostsOption)) {
                    String[] cassandraHosts = parseCassandraHosts(optionValue.toString());
                    configuration.put(option, cassandraHosts);
                } else if (option.equals(sqlServerTypeOption)) {
                    if ("oracle".equals(optionValue)) {
                        configuration.put(option, DatabaseType.Oracle);
                    } else {
                        configuration.put(option, DatabaseType.Postgres);
                    }
                } else if (option.equals(sqlPostgresServerOption)) {
                    boolean value = tryParseBoolean(optionValue.toString(), true);
                    if (value == true) {
                        configuration.put(sqlServerTypeOption, DatabaseType.Postgres);
                    }
                } else if (option.equals(sqlOracleServerOption)) {
                    boolean value = tryParseBoolean(optionValue.toString(), true);
                    if (value == true) {
                        configuration.put(sqlServerTypeOption, DatabaseType.Oracle);
                    }
                } else if (option.getType().equals(Boolean.class)) {
                    configuration.put(option, tryParseBoolean(optionValue.toString(), true));
                } else if (option.getType().equals(Integer.class)) {
                    configuration.put(option, tryParseInteger(optionValue.toString(), 0));
                } else {
                    configuration.put(option, optionValue.toString());
                }
            }
        }
    } catch (Exception e) {
        log.error("Unable to load or process the configuration file.", e);
        System.exit(1);
    }
}