Example usage for org.apache.commons.cli OptionBuilder withLongOpt

List of usage examples for org.apache.commons.cli OptionBuilder withLongOpt

Introduction

In this page you can find the example usage for org.apache.commons.cli OptionBuilder withLongOpt.

Prototype

public static OptionBuilder withLongOpt(String newLongopt) 

Source Link

Document

The next Option created will have the following long option value.

Usage

From source file:de.uniwue.info2.main.CommandLineInterpreter.java

@SuppressWarnings("static-access")
public static void main(String[] args) {

    /*-------------------------------------------------------- */
    /*---------------SETTING TARGET LANGUAGE------------------ */
    /*-------------------------------------------------------- */
    LanguageFactory languageFactory = new LanguageFactory();

    CommandLine line = null;//from  www . jav a  2 s.c  o  m
    CommandLineParser parser = new BasicParser();
    Options options = new Options();
    // options to display in the help page
    Options options_short = new Options();

    // add help option
    Option help_option = new Option(HELP_OPTION_SHORT, HELP_OPTION, false, HELP_DESCRIPTION);
    options.addOption(help_option);
    options_short.addOption(help_option);
    // add extended help option
    Option help2_option = new Option(HELP2_OPTION_SHORT, HELP2_OPTION, false, HELP2_DESCRIPTION);
    options.addOption(help2_option);
    options_short.addOption(help2_option);
    // add optional operations option
    options.addOption(new Option(OPTIONAL_OPTION_SHORT, OPTIONAL_OPTION, false, OPTIONAL_DESCRIPTION));
    options.addOption(new Option(BIG_ENDIAN_OPTION_SHORT, BIG_ENDIAN_OPTION, false, BIG_ENDIAN_DESCRIPTION));
    options.addOption(
            new Option(LITTLE_ENDIAN_OPTION_SHORT, LITTLE_ENDIAN_OPTION, false, LITTLE_ENDIAN_DESCRIPTION));
    // add optional operations config option
    options.addOption(OptionBuilder.withLongOpt(OPTIONAL_FUNCTIONS_CONFIG_OPTION)
            .withArgName(OPTIONAL_FUNCTIONS_CONFIG_ARGUMENT)
            .withDescription(OPTIONAL_FUNCTIONS_CONFIG_DESCRIPTION).hasArg()
            .create(OPTIONAL_FUNCTIONS_CONFIG_SHORT));
    // add dsl option
    Option dsl_option = OptionBuilder.withLongOpt(DSL_OPTION).withArgName(DSL_ARGUMENT)
            .withDescription(DSL_DESCRIPTION).hasArg().isRequired().create(DSL_OPTION_SHORT);
    options.addOption(dsl_option);
    options_short.addOption(dsl_option);
    // add output-folder option
    Option output_option = OptionBuilder.withLongOpt(OUTPUT_OPTION).isRequired().withArgName(OUTPUT_ARGUMENT)
            .withDescription(OUTPUT_DESCRIPTION).hasArg().create(OUTPUT_OPTION_SHORT);
    options.addOption(output_option);
    options_short.addOption(output_option);

    // count possible language-specifications
    short optionCounter = 1;

    // get all possible language-specifications from language-factory and iterate through them
    List<LanguageSpecification> lSpecs = languageFactory.getAvailableLanguageSpecifications_();

    for (LanguageSpecification lSpec : lSpecs) {
        // get all possible unit-specifications for current language and iterate through them
        List<UnitTestLibrarySpecification> uSpecs = languageFactory
                .getAvailableUnitTestLibraries_(lSpec.getOptionName());
        String languageDescriptionAll = LANGUAGE_SPECIFICATION + lSpec.getLanguageName();
        String languageCounter = "s" + INDEX.format(optionCounter++);

        for (UnitTestLibrarySpecification uSpec : uSpecs) {
            // get all possible arithmetic-library-specifications for current language and iterate through
            // them
            List<ArithmeticLibrarySpecification> aSpecs = languageFactory
                    .getAvailableArithmeticLibraries_(lSpec.getOptionName());
            for (ArithmeticLibrarySpecification aSpec : aSpecs) {
                String languageDescription = "Generate unit-test for " + lSpec.getLanguageName() + "\n*["
                        + uSpec.getLibraryName() + " - " + uSpec.getVersion() + "]\n*[" + aSpec.getLibraryName()
                        + " - " + aSpec.getVersion() + "]";

                // if there is more than one option, generate suitable option-names and add them all to
                // commandline options
                if (uSpecs.size() > 1 || aSpecs.size() > 1) {
                    options.addOption(OptionBuilder
                            .withLongOpt(lSpec.getOptionName() + "_" + uSpec.getOptionName() + "_"
                                    + aSpec.getOptionName())
                            .withDescription(languageDescription).hasArg(false)
                            .create("s" + INDEX.format(optionCounter++)));
                } else {
                    // if there is only one option, use language-name as option-name
                    languageDescriptionAll = languageDescription;
                }
            }
            // add specifications to options
            options.addOption(OptionBuilder.withLongOpt(lSpec.getOptionName())
                    .withDescription(languageDescriptionAll).hasArg(false).create(languageCounter));
        }
    }

    /*-------------------------------------------------------- */
    /*-------------------PARSE USER INPUT--------------------- */
    /*-------------------------------------------------------- */
    try {
        // manual search for help-arguments
        for (String arg : args) {
            arg = arg.trim().replace("-", "");
            if (arg.equals(HELP_OPTION_SHORT) || arg.equals(HELP_OPTION)) {
                printHelp(options_short);
                return;
            }
            if (arg.equals(HELP2_OPTION_SHORT) || arg.equals(HELP2_OPTION)) {
                printExtendedHelp(options);
                return;
            }
        }

        // parse arguments   
        line = parser.parse(options, args);

        File dsl_file = null;
        File output_folder = null;
        File optional_config = null;
        Properties optional_operations = null;
        Boolean optional = false;
        Boolean little_endian = null;
        ArrayList<String> optional_exceptions = new ArrayList<String>();

        // if help-option found print help
        if (line.hasOption(HELP2_OPTION_SHORT) || args.length == 0) {
            printExtendedHelp(options);
            return;
        }

        // if help-option found print help
        if (line.hasOption(HELP_OPTION_SHORT) || args.length == 0) {
            System.out.println("\n");
            printHelp(options_short);
            return;
        }

        if (line.hasOption(OPTIONAL_OPTION_SHORT)) {
            optional = true;
        }

        if (line.hasOption(LITTLE_ENDIAN_OPTION)) {
            little_endian = true;
        }

        if (line.hasOption(BIG_ENDIAN_OPTION)) {
            little_endian = false;
        }

        // if dsl-option found, check if file exists and is readable
        // print help if error occurs
        if (line.hasOption(DSL_OPTION_SHORT)) {
            dsl_file = new File(line.getOptionValue(DSL_OPTION_SHORT));
            if (!dsl_file.exists()) {
                System.err.println("\n" + SEPERATOR + "\n" + "ERROR - DSL-file doesn't exist:\n" + dsl_file
                        + "\n" + SEPERATOR + "\n");
                printHelp(options_short);
                return;
            } else if (dsl_file.isDirectory()) {
                System.err.println("\n" + SEPERATOR + "\n" + "ERROR - DSL-file is a directory:\n" + dsl_file
                        + "\n" + SEPERATOR + "\n");
                printHelp(options_short);
                return;
            } else if (!dsl_file.canRead()) {
                System.err.println("\n" + SEPERATOR + "\n" + "ERROR - Need read-permission for DSL-file:\n"
                        + dsl_file + "\n" + SEPERATOR + "\n");
                printHelp(options_short);
                return;
            }
        }

        // if output-option found, check if folder exists and if write-permission was granted
        // print help if error occurs
        if (line.hasOption(OUTPUT_OPTION_SHORT)) {
            output_folder = new File(line.getOptionValue(OUTPUT_OPTION_SHORT));
            if (!output_folder.exists()) {
                System.err.println("\n" + SEPERATOR + "\n" + "ERROR - Output-folder doesn't exist:\n"
                        + output_folder + "\n" + SEPERATOR + "\n");
                printHelp(options_short);
                return;
            } else if (!output_folder.isDirectory()) {
                System.err.println("\n" + SEPERATOR + "\n" + "ERROR - Output-folder is not a directory:\n"
                        + output_folder + "\n" + SEPERATOR + "\n");
                printHelp(options_short);
                return;
            } else if (!output_folder.canWrite() || !output_folder.canRead()) {
                System.err.println("\n" + SEPERATOR + "\n" + "ERROR - Missing permissions for output-folder:\n"
                        + output_folder + "\n" + SEPERATOR + "\n");
                printHelp(options_short);
                return;
            }
        }

        if (line.hasOption(OPTIONAL_FUNCTIONS_CONFIG_SHORT)) {
            optional_config = new File(line.getOptionValue(OPTIONAL_FUNCTIONS_CONFIG_OPTION));
            if (!dsl_file.exists()) {
                System.err.println("\n" + SEPERATOR + "\n" + "ERROR - config-file doesn't exist:\n" + dsl_file
                        + "\n" + SEPERATOR + "\n");
                printExtendedHelp(options);
                return;
            } else if (dsl_file.isDirectory()) {
                System.err.println("\n" + SEPERATOR + "\n" + "ERROR - config-file is a directory:\n" + dsl_file
                        + "\n" + SEPERATOR + "\n");
                printExtendedHelp(options);
                return;
            } else if (!dsl_file.canRead()) {
                System.err.println("\n" + SEPERATOR + "\n" + "ERROR - Need read-permission for config-file:\n"
                        + dsl_file + "\n" + SEPERATOR + "\n");
                printExtendedHelp(options);
                return;
            }
        }

        if (optional_config != null) {
            optional_operations = new Properties();
            BufferedInputStream stream = new BufferedInputStream(new FileInputStream(optional_config));
            optional_operations.load(stream);
            stream.close();
            String optional_prop = optional_operations.getProperty("GENERATE_OPTIONAL");
            if (optional_prop != null) {
                if (optional_prop.trim().toLowerCase().equals("true")) {
                    optional = true;
                } else if (optional_prop.trim().toLowerCase().equals("false")) {
                    optional = false;
                } else if (!optional_prop.trim().isEmpty()) {
                    System.err.println("\n" + SEPERATOR + "\n"
                            + "ERROR - Syntax incorrect in config-file:\nUse \"true\" or \"false\" for \"GENERATE_OPTIONAL\"\n"
                            + SEPERATOR + "\n");
                    printExtendedHelp(options);
                    return;
                }
            }
            String exceptions = optional_operations.getProperty("EXCLUSIONS");
            if (exceptions != null) {
                for (String exc : optional_operations.getProperty("EXCLUSIONS").split(";")) {
                    optional_exceptions.add(exc.trim());
                }
            }
        }

        /*-------------------------------------------------------- */
        /*-------------------START GENERATING--------------------- */
        /*-------------------------------------------------------- */

        // instantiate generator for unit-tests
        TestcaseGenerator mainGenerator = new TestcaseGenerator(dsl_file, output_folder);

        boolean overrideDefaultSpecs = false;

        // check if user input contains a language-specifications
        // if user specified language, set overrideDefaultSpecs to true, so that only given specifications
        // are used
        for (int i = 1; i <= optionCounter; i++) {
            String opt = "s" + INDEX.format(i);
            if (line.hasOption(opt)) {
                LanguageSpecification targetSpecification = languageFactory
                        .getLanguageSpecification(options.getOption(opt).getLongOpt());
                String output = (GENERATING_DIALOG + targetSpecification.getLanguageName());

                // finally generate unit-test for current language-specification
                boolean successful = mainGenerator.generateUnitTest(targetSpecification, optional,
                        optional_exceptions, little_endian);

                if (successful) {
                    System.out.println(output + "\n--> Successfully generated.");
                } else {
                    System.err.println(output + "\n--> ERROR - see logfile");
                }
                overrideDefaultSpecs = true;
            }
        }

        // skip, if user already defined one language-specification
        // if user did not define language-specification, generate unit-tests for all
        // possible language-specifications (default)
        if (!overrideDefaultSpecs) {
            for (int i = 0; i < lSpecs.size(); i++) {
                LanguageSpecification specification = languageFactory
                        .getLanguageSpecification(lSpecs.get(i).getOptionName());

                String output = INDEX.format(i + 1) + " - " + GENERATING_DIALOG
                        + specification.getLanguageName();

                // finally generate unit-test for current language-specification
                boolean successful = mainGenerator.generateUnitTest(specification, optional,
                        optional_exceptions, little_endian);

                if (successful) {
                    System.out.println(output + "\n--> Successfully generated.");
                } else {
                    System.err.println(output + "\n--> ERROR - see logfile");
                }
            }
        }

    } catch (ParseException | IOException p) {
        System.err.println("\n" + SEPERATOR + "\n" + "ERROR - WRONG ARGUMENTS:\n" + p.getMessage() + "\n"
                + SEPERATOR + "\n");
        printHelp(options_short);
        System.out.println("\n");
    }
}

From source file:ar.edu.taco.TacoMain.java

/**
 * @param args/*from  www .j av  a2 s  .  co  m*/
 */
@SuppressWarnings({ "static-access" })
public static void main(String[] args) {
    @SuppressWarnings("unused")
    int loopUnrolling = 3;

    String tacoVersion = getManifestAttribute(Attributes.Name.IMPLEMENTATION_VERSION);
    String tacoCreatedBy = getManifestAttribute(new Name("Created-By"));

    System.out.println("TACO: Taco static analysis tool.");
    System.out.println("Created By: " + tacoCreatedBy);
    System.out.println("Version: " + tacoVersion);
    System.out.println("");
    System.out.println("");

    Option helpOption = new Option("h", "help", false, "print this message");
    Option versionOption = new Option("v", "version", false, "shows version");

    Option configFileOption = OptionBuilder.withArgName("path").withLongOpt("configFile").hasArg()
            .withDescription("set the configuration file").create("cf");
    Option classToCheckOption = OptionBuilder.withArgName("classname").withLongOpt("classToCheck").hasArg()
            .withDescription("set the class to be checked").create('c');
    Option methodToCheckOption = OptionBuilder.withArgName("methodname").withLongOpt("methodToCheck").hasArg()
            .withDescription("set the method to be checked").create('m');
    Option dependenciesOption = OptionBuilder.withArgName("classname").withLongOpt("dependencies").hasArgs()
            .withDescription("additional sources to be parsed").create('d');
    Option relevantClassesOption = OptionBuilder.withArgName("classname").withLongOpt("relevantClasses")
            .hasArgs().withDescription("Set the relevant classes to be used").create("rd");
    Option loopsOptions = OptionBuilder.withArgName("integer").withLongOpt("unroll").hasArg()
            .withDescription("set number of loop unrollings").create('u');
    Option bitOptions = OptionBuilder.withArgName("integer").withLongOpt("width").hasArg()
            .withDescription("set bit width").create('w');
    Option instOptions = OptionBuilder.withArgName("integer").withLongOpt("bound").hasArg()
            .withDescription("set class bound").create('b');
    Option skolemizeOption = OptionBuilder.withLongOpt("skolemize")
            .withDescription("set whether or not skolemize").create("sk");
    Option simulateOption = OptionBuilder.withLongOpt("simulate")
            .withDescription("run method instead of checking").create("r");
    Option modularReasoningOption = OptionBuilder.withLongOpt("modularReasoning")
            .withDescription("check method using modular reasoning").create("mr");
    Option relevancyAnalysisOption = OptionBuilder.withLongOpt("relevancyAnalysis")
            .withDescription("calculate the needed relevantClasses").create("ra");
    Option scopeRestrictionOption = OptionBuilder.withLongOpt("scopeRestriction")
            .withDescription("restrict signature scope to value set in -b option").create("sr");
    /*
     * Option noVerifyOption = OptionBuilder.withLongOpt(
     * "noVerify").withDescription(
     * "builds output but does not invoke verification engine").create(
     * "nv");
     */
    Options options = new Options();
    options.addOption(helpOption);
    options.addOption(versionOption);
    options.addOption(configFileOption);
    options.addOption(classToCheckOption);
    options.addOption(methodToCheckOption);
    options.addOption(dependenciesOption);
    options.addOption(relevantClassesOption);
    options.addOption(loopsOptions);
    options.addOption(bitOptions);
    options.addOption(instOptions);
    options.addOption(skolemizeOption);
    options.addOption(simulateOption);
    options.addOption(modularReasoningOption);
    options.addOption(relevancyAnalysisOption);
    options.addOption(scopeRestrictionOption);
    // options.addOption(noVerifyOption)

    String configFileArgument = null;
    Properties overridingProperties = new Properties();
    TacoCustomScope tacoScope = new TacoCustomScope();

    // create the parser
    CommandLineParser parser = new PosixParser();

    try {
        // parse the command line arguments
        CommandLine line = parser.parse(options, args);

        // help
        if (line.hasOption(helpOption.getOpt())) {
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp(120, CMD, HEADER, options, FOOTER, true);
            return;
        }

        // version
        if (line.hasOption(versionOption.getOpt())) {
            System.out.println(FOOTER);
            System.out.println("");
            return;
        }

        // Configuration file
        if (line.hasOption(configFileOption.getOpt())) {
            configFileArgument = line.getOptionValue(configFileOption.getOpt());
        }

        // class to check
        if (line.hasOption(classToCheckOption.getOpt())) {
            overridingProperties.put(TacoConfigurator.CLASS_TO_CHECK_FIELD,
                    line.getOptionValue(classToCheckOption.getOpt()));
        }

        // method to check
        if (line.hasOption(methodToCheckOption.getOpt())) {
            String methodtoCheck = line.getOptionValue(methodToCheckOption.getOpt());

            if (!methodtoCheck.matches("^[A-Za-z0-9_-]+_[0-9]")) {
                methodtoCheck = methodtoCheck + "_0";
            }
            overridingProperties.put(TacoConfigurator.METHOD_TO_CHECK_FIELD, methodtoCheck);
        }

        // Dependencies classes
        if (line.hasOption(dependenciesOption.getOpt())) {
            String dependenciesClasses = "";
            for (String aDependencyClass : line.getOptionValues(dependenciesOption.getOpt())) {
                dependenciesClasses += aDependencyClass;
            }
            overridingProperties.put(TacoConfigurator.CLASSES_FIELD, dependenciesClasses);
        }

        // Relevant classes
        if (line.hasOption(relevantClassesOption.getOpt())) {
            String relevantClasses = "";
            for (String aRelevantClass : line.getOptionValues(relevantClassesOption.getOpt())) {
                relevantClasses += aRelevantClass;
            }
            overridingProperties.put(TacoConfigurator.RELEVANT_CLASSES, relevantClasses);
        }

        // Loop unrolling
        if (line.hasOption(loopsOptions.getOpt())) {
            loopUnrolling = Integer.parseInt(line.getOptionValue(loopsOptions.getOpt()));
        }

        // Int bitwidth
        if (line.hasOption(bitOptions.getOpt())) {
            String alloy_bitwidth_str = line.getOptionValue(bitOptions.getOpt());
            overridingProperties.put(TacoConfigurator.BITWIDTH, alloy_bitwidth_str);
            int alloy_bitwidth = new Integer(alloy_bitwidth_str);
            tacoScope.setAlloyBitwidth(alloy_bitwidth);
        }

        // instances scope
        if (line.hasOption(instOptions.getOpt())) {
            String assertionsArguments = "for " + line.getOptionValue(instOptions.getOpt());
            overridingProperties.put(TacoConfigurator.ASSERTION_ARGUMENTS, assertionsArguments);
        }

        // Skolemize
        if (line.hasOption(skolemizeOption.getOpt())) {
            overridingProperties.put(TacoConfigurator.SKOLEMIZE_INSTANCE_INVARIANT, false);
            overridingProperties.put(TacoConfigurator.SKOLEMIZE_INSTANCE_ABSTRACTION, false);
        }

        // Simulation
        if (line.hasOption(simulateOption.getOpt())) {
            overridingProperties.put(TacoConfigurator.INCLUDE_SIMULATION_PROGRAM_DECLARATION, true);
            overridingProperties.put(TacoConfigurator.GENERATE_CHECK, false);
            overridingProperties.put(TacoConfigurator.GENERATE_RUN, false);
        }

        // Modular Reasoning
        if (line.hasOption(modularReasoningOption.getOpt())) {
            overridingProperties.put(TacoConfigurator.MODULAR_REASONING, true);
        }

        // Relevancy Analysis
        if (line.hasOption(relevancyAnalysisOption.getOpt())) {
            overridingProperties.put(TacoConfigurator.RELEVANCY_ANALYSIS, true);
        }

    } catch (ParseException e) {
        System.err.println("Command line parsing failed: " + e.getMessage());
    }

    try {

        System.out.println("****** Starting Taco (version. " + tacoVersion + ") ****** ");
        System.out.println("");

        File file = new File("config/log4j.xml");
        if (file.exists()) {
            DOMConfigurator.configure("config/log4j.xml");
        } else {
            System.err.println("log4j:WARN File config/log4j.xml not found");
        }

        TacoMain main = new TacoMain();

        // BUILD TacoScope 

        //
        main.run(configFileArgument, overridingProperties);

    } catch (IllegalArgumentException e) {
        System.err.println("Error found:");
        System.err.println(e.getMessage());
    } catch (MethodToCheckNotFoundException e) {
        System.err.println("Error found:");
        System.err.println("Method to check was not found. Please verify config file, or add -m option");
    } catch (TacoException e) {
        System.err.println("Error found:");
        System.err.println(e.getMessage());
    }
}

From source file:io.sightly.tck.TCK.java

public static void main(String[] args) {

    CommandLineParser parser = new PosixParser();
    Options options = new Options();
    options.addOption(OptionBuilder.withLongOpt(CLI_EXTRACT).withDescription(CLI_EXTRACT_DESCRIPTION)
            .hasOptionalArg().withArgName("DIR").create());
    options.addOption(OptionBuilder.withLongOpt(CLI_URL).withDescription(CLI_URL_DESCRIPTION).hasOptionalArg()
            .withArgName("URL").create());
    options.addOption(OptionBuilder.withLongOpt(CLI_AUTH_USER).withDescription(CLI_AUTH_USER_DESCRIPTION)
            .hasOptionalArg().withArgName("USER").create());
    options.addOption(OptionBuilder.withLongOpt(CLI_AUTH_PASS).withDescription(CLI_AUTH_PASS_DESCRIPTION)
            .hasOptionalArg().withArgName("PASS").create());
    try {//from  www. j  a  v a 2s.  c o m
        CommandLine line = parser.parse(options, args);
        if (!line.iterator().hasNext()) {
            printUsage(options);
            die();
        } else if (line.hasOption(CLI_EXTRACT)) {
            String extractDir = line.getOptionValue(CLI_EXTRACT);
            if (StringUtils.isEmpty(extractDir)) {
                // assume user wants to extract stuff in current directory
                extractDir = System.getProperty("user.dir");
            }
            INSTANCE.extract(extractDir);
            LOG.info("Extracted testing resources in folder {}.", extractDir + File.separator + TESTFILES);
        } else {
            if (line.hasOption(CLI_URL)) {
                String url = line.getOptionValue(CLI_URL);
                if (StringUtils.isEmpty(url)) {
                    LOG.error("Missing value for --" + CLI_URL + " command line option.");
                    printUsage(options);
                    die();
                }
                System.setProperty(Constants.SYS_PROP_SERVER_URL, url);
            }
            if (line.hasOption(CLI_AUTH_USER) || line.hasOption(CLI_AUTH_PASS)) {
                String user = line.getOptionValue(CLI_AUTH_USER);
                if (StringUtils.isEmpty(user)) {
                    LOG.error("Missing value for --" + CLI_AUTH_USER + " command line option");
                    printUsage(options);
                    die();
                }
                String pass = line.getOptionValue(CLI_AUTH_PASS);
                if (StringUtils.isEmpty(pass)) {
                    LOG.error("Missing value for --" + CLI_AUTH_PASS + " command line option");
                    printUsage(options);
                    die();
                }
                System.setProperty(Constants.SYS_PROP_USER, user);
                System.setProperty(Constants.SYS_PROP_PASS, pass);
            }
            INSTANCE.run();
        }

    } catch (ParseException e) {
        printUsage(options);
        die();
    } catch (IOException e) {
        LOG.error("IO Error.", e);
        die();
    }
}

From source file:de.tudarmstadt.ukp.teaching.uima.nounDecompounding.web1t.LuceneIndexer.java

/**
 * Execute the indexer. Following parameter are allowed:
 * /*from w  w w.  j  a v a  2  s  . c  o m*/
 *   * --web1t The folder with all extracted n-gram files
 *   * --outputPath The lucene index folder
 *   * --index (optional) Number of how many indexes should be created. Default: 1
 * 
 * @param args
 */
@SuppressWarnings("static-access")
public static void main(String[] args) {
    Options options = new Options();
    options.addOption(OptionBuilder.withLongOpt("web1t")
            .withDescription("Folder with the web1t extracted documents").hasArg().isRequired().create());
    options.addOption(OptionBuilder.withLongOpt("outputPath")
            .withDescription("File, where the index should be created").hasArg().isRequired().create());
    options.addOption(OptionBuilder.withLongOpt("index")
            .withDescription("(optional) Number of how many indexes should be created. Default: 1").hasArg()
            .create());
    options.addOption(OptionBuilder.withLongOpt("igerman98").withDescription(
            "(optional) If this argument is set, only words of the german dictionary will be added to the index")
            .create());

    CommandLineParser parser = new PosixParser();
    try {
        CommandLine cmd = parser.parse(options, args);

        int i = 1;
        if (cmd.hasOption("index")) {
            i = Integer.valueOf(cmd.getOptionValue("index"));
        }

        LuceneIndexer indexer = new LuceneIndexer(new File(cmd.getOptionValue("web1t")),
                new File(cmd.getOptionValue("outputPath")), i);

        if (cmd.hasOption("igerman98")) {
            indexer.setDictionary(new IGerman98Dictionary(new File("src/main/resources/de_DE.dic"),
                    new File("src/main/resources/de_DE.aff")));
        }

        indexer.index();
    } catch (Exception e) {
        System.err.println("Error: " + e.getMessage());

        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("LuceneIndexer", options);
    }
}

From source file:com.github.andreax79.meca.Main.java

@SuppressWarnings("static-access")
public static void main(String[] args) {
    // create the command line parser
    CommandLineParser parser = new PosixParser();

    // create the Options
    Options options = new Options();
    options.addOption("X", "suppress-output", false, "don't create the output file");

    OptionGroup boundariesOptions = new OptionGroup();
    boundariesOptions.addOption(new Option("P", "periodic", false, "periodic boundaries (default)"));
    boundariesOptions.addOption(new Option("F", "fixed", false, "fixed-value boundaries"));
    boundariesOptions.addOption(new Option("A", "adiabatic", false, "adiabatic boundaries"));
    boundariesOptions.addOption(new Option("R", "reflective", false, "reflective boundaries"));
    options.addOptionGroup(boundariesOptions);

    OptionGroup colorOptions = new OptionGroup();
    colorOptions.addOption(new Option("bn", "black-white", false, "black and white color scheme (default)"));
    colorOptions.addOption(new Option("ca", "activation-color", false, "activation color scheme"));
    colorOptions.addOption(new Option("co", "omega-color", false, "omega color scheme"));
    options.addOptionGroup(colorOptions);

    options.addOption(OptionBuilder.withLongOpt("rule").withDescription("rule number (required)").hasArg()
            .withArgName("rule").create());

    options.addOption(OptionBuilder.withLongOpt("width").withDescription("space width (required)").hasArg()
            .withArgName("width").create());

    options.addOption(OptionBuilder.withLongOpt("steps").withDescription("number of steps (required)").hasArg()
            .withArgName("steps").create());

    options.addOption(OptionBuilder.withLongOpt("alpha").withDescription("memory factor (default 0)").hasArg()
            .withArgName("alpha").create());

    options.addOption(OptionBuilder.withLongOpt("pattern").withDescription("inititial pattern").hasArg()
            .withArgName("pattern").create());

    options.addOption("s", "single-seed", false, "single cell seed");
    options.addOption("si", "single-seed-inverse", false, "all 1 except one cell");

    options.addOption(OptionBuilder.withLongOpt("update-patter")
            .withDescription("update patter (valid values are " + UpdatePattern.validValues() + ")").hasArg()
            .withArgName("updatepatter").create());

    // test// w  w  w . j ava  2 s  . c  o m
    // args = new String[]{ "--rule=10", "--steps=500" , "--width=60", "-P" , "-s" };

    try {
        // parse the command line arguments
        CommandLine line = parser.parse(options, args);

        if (!line.hasOption("rule"))
            throw new ParseException("no rule number (use --rule=XX)");
        int rule;
        try {
            rule = Integer.parseInt(line.getOptionValue("rule"));
            if (rule < 0 || rule > 15)
                throw new ParseException("invalid rule number");
        } catch (NumberFormatException ex) {
            throw new ParseException("invalid rule number");
        }

        if (!line.hasOption("width"))
            throw new ParseException("no space width (use --width=XX)");
        int width;
        try {
            width = Integer.parseInt(line.getOptionValue("width"));
            if (width < 1)
                throw new ParseException("invalid width");
        } catch (NumberFormatException ex) {
            throw new ParseException("invalid width");
        }

        if (!line.hasOption("steps"))
            throw new ParseException("no number of steps (use --steps=XX)");
        int steps;
        try {
            steps = Integer.parseInt(line.getOptionValue("steps"));
            if (width < 1)
                throw new ParseException("invalid number of steps");
        } catch (NumberFormatException ex) {
            throw new ParseException("invalid number of steps");
        }

        double alpha = 0;
        if (line.hasOption("alpha")) {
            try {
                alpha = Double.parseDouble(line.getOptionValue("alpha"));
                if (alpha < 0 || alpha > 1)
                    throw new ParseException("invalid alpha");
            } catch (NumberFormatException ex) {
                throw new ParseException("invalid alpha");
            }
        }

        String pattern = null;
        if (line.hasOption("pattern")) {
            pattern = line.getOptionValue("pattern");
            if (pattern != null)
                pattern = pattern.trim();
        }

        if (line.hasOption("single-seed"))
            pattern = "S";
        else if (line.hasOption("single-seed-inverse"))
            pattern = "SI";

        UpdatePattern updatePatter = UpdatePattern.synchronous;
        if (line.hasOption("update-patter")) {
            try {
                updatePatter = UpdatePattern.getUpdatePattern(line.getOptionValue("update-patter"));
            } catch (IllegalArgumentException ex) {
                throw new ParseException(ex.getMessage());
            }
        }

        Boundaries boundaries = Boundaries.periodic;
        if (line.hasOption("periodic"))
            boundaries = Boundaries.periodic;
        else if (line.hasOption("fixed"))
            boundaries = Boundaries.fixed;
        else if (line.hasOption("adiabatic"))
            boundaries = Boundaries.adiabatic;
        else if (line.hasOption("reflective"))
            boundaries = Boundaries.reflective;

        ColorScheme colorScheme = ColorScheme.noColor;
        if (line.hasOption("black-white"))
            colorScheme = ColorScheme.noColor;
        else if (line.hasOption("activation-color"))
            colorScheme = ColorScheme.activationColor;
        else if (line.hasOption("omega-color"))
            colorScheme = ColorScheme.omegaColor;

        Output output = Output.all;
        if (line.hasOption("suppress-output"))
            output = Output.noOutput;

        Main.drawRule(rule, width, boundaries, updatePatter, steps, alpha, pattern, output, colorScheme);

    } catch (ParseException ex) {
        System.err.println("Copyright (C) 2009 Andrea Bonomi - <andrea.bonomi@gmail.com>");
        System.err.println();
        System.err.println("https://github.com/andreax79/one-neighbor-binary-cellular-automata");
        System.err.println();
        System.err.println("This program is free software; you can redistribute it and/or modify it");
        System.err.println("under the terms of the GNU General Public License as published by the");
        System.err.println("Free Software Foundation; either version 2 of the License, or (at your");
        System.err.println("option) any later version.");
        System.err.println();
        System.err.println("This program is distributed in the hope that it will be useful, but");
        System.err.println("WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY");
        System.err.println("or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License");
        System.err.println("for more details.");
        System.err.println();
        System.err.println("You should have received a copy of the GNU General Public License along");
        System.err.println("with this program; if not, write to the Free Software Foundation, Inc.,");
        System.err.println("59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.)");
        System.err.println();
        System.err.println(ex.getMessage());
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("main", options);

    } catch (IOException ex) {
        System.err.println("IO exception:" + ex.getMessage());
    }

}

From source file:com.comcast.oscar.cli.commands.FullTLVDisplay.java

/**
 * Set option parameters for command Full TLV display
 * @return Option/*from  w  w w  .j  a v a  2s  .c  om*/
 */
public static final Option OptionParameters() {
    OptionBuilder.withValueSeparator(' ');
    OptionBuilder.withLongOpt("fulltlvdisplay");
    OptionBuilder
            .withDescription("Display all TLVs available in the dictionary for the defined specification.");
    return OptionBuilder.create("ftd");
}

From source file:com.bachelor.boulmier.workmaster.WorkMaster.java

@SuppressWarnings("static-access")
private static void defineOptions() {
    options = new Options();
    Option maxVMOption = OptionBuilder.withLongOpt(MasterConfig.CMD.MAXVMLONGOPT)
            .withArgName(MasterConfig.CMD.MAXVMARG).withDescription(MasterConfig.CMD.MAXVMDESC)
            .withType(MasterConfig.CMD.MAXVMTYPE).hasArg().create(),
            remoteWebServer = OptionBuilder.withLongOpt(MasterConfig.CMD.REMOTEWSLONGOPT)
                    .withArgName(MasterConfig.CMD.REMOTEWSARG).withDescription(MasterConfig.CMD.REMOTEWSDESC)
                    .hasArg().create(),//from   w  w  w . j  a v a  2  s  .co  m
            verboseOption = OptionBuilder.withLongOpt(MasterConfig.CMD.VERBOSELONGOPT)
                    .withDescription(MasterConfig.CMD.VERBOSEDESC).create(),
            debugOption = OptionBuilder.withDescription(MasterConfig.CMD.DEBUGDESC)
                    .withLongOpt(MasterConfig.CMD.DEBUGLONGOPT).create(),
            cli = OptionBuilder.withLongOpt(MasterConfig.CMD.CLILONGOPT)
                    .withDescription(MasterConfig.CMD.CLIDESC).create(),
            helpOption = OptionBuilder.withLongOpt(MasterConfig.CMD.HELPLONGOPT)
                    .withDescription(MasterConfig.CMD.HELPDESC).create();

    options.addOption(maxVMOption);
    options.addOption(remoteWebServer);
    options.addOption(cli);
    options.addOption(debugOption);
    options.addOption(verboseOption);
    options.addOption(helpOption);
}

From source file:com.comcast.oscar.cli.commands.Key.java

/**
 * Set option parameters for command Key
 * @return Option/*from  w  w  w . j  a  v a2 s . co  m*/
 */
public static Option OptionParameters() {
    OptionBuilder.withArgName("key filename");
    OptionBuilder.hasArgs(1);
    OptionBuilder.hasOptionalArgs();
    OptionBuilder.withValueSeparator(' ');
    OptionBuilder.withLongOpt("key");
    OptionBuilder.withDescription("Use this sharedsecret to compile the file - DOCSIS ONLY.");
    return OptionBuilder.create("k");
}

From source file:com.comcast.oscar.cli.commands.TLV.java

/**
 * Set option parameters for command TLV
 * @return Option/*from  w  ww . j a  v a 2  s .c o m*/
 */
public static final Option OptionParameters() {
    OptionBuilder.withArgName("TLV");
    OptionBuilder.hasArgs(1);
    OptionBuilder.hasOptionalArgs();
    OptionBuilder.withValueSeparator(' ');
    OptionBuilder.withLongOpt("tlv");
    OptionBuilder.withDescription("Insert this TLV during file compilation.");
    return OptionBuilder.create("t");
}

From source file:com.comcast.oscar.cli.commands.Firmware.java

/**
 * Set option parameters for command Firmware
 * @return Option//from   w w w .j a  va2 s .  c om
 */
public static final Option OptionParameters() {
    OptionBuilder.withArgName("filename");
    OptionBuilder.hasArgs(1);
    OptionBuilder.hasOptionalArgs();
    OptionBuilder.withValueSeparator(' ');
    OptionBuilder.withLongOpt("firmware");
    OptionBuilder.withDescription("Insert this firmware during file compilation.");
    return OptionBuilder.create("f");
}