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

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

Introduction

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

Prototype

public String getOpt() 

Source Link

Document

Retrieve the name of this Option.

Usage

From source file:es.eucm.ead.exporter.ExporterMain.java

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

    Options options = new Options();

    Option help = new Option("h", "help", false, "print this message");
    Option quiet = new Option("q", "quiet", false, "be extra quiet");
    Option verbose = new Option("v", "verbose", false, "be extra verbose");

    Option legacy = OptionBuilder.withArgName("s> <t").hasArgs(3)
            .withDescription(/*  w w  w. j ava2 s .  c  om*/
                    "source is a version 1.x game; must specify\n" + "<simplify> if 'true', simplifies result\n"
                            + "<translate> if 'true', enables translation")
            .withLongOpt("import").create("i");

    Option war = OptionBuilder.withArgName("web-base").hasArg()
            .withDescription("WAR packaging (web app); " + "must specify\n<web-base> the base WAR directory")
            .withLongOpt("war").create("w");

    Option jar = OptionBuilder.withDescription("JAR packaging (desktop)").withLongOpt("jar").create("j");

    Option apk = OptionBuilder.withArgName("props> <adk> <d").hasArgs(3)
            .withDescription("APK packaging (android); must specify \n" + "<props> (a properties file) \n"
                    + "<adk> (location of the ADK to use) \n" + "<deploy> ('true' to install & deploy)")
            .withLongOpt("apk").create("a");

    // EAD option
    Option ead = OptionBuilder.withDescription("EAD packaging (eAdventure)").withLongOpt("ead").create("e");

    options.addOption(legacy);
    options.addOption(help);
    options.addOption(quiet);
    options.addOption(verbose);
    options.addOption(jar);
    options.addOption(war);
    options.addOption(apk);
    options.addOption(ead);

    CommandLineParser parser = new PosixParser();
    CommandLine cmd;
    try {
        cmd = parser.parse(options, args);
    } catch (ParseException pe) {
        System.err.println("Error parsing command-line: " + pe.getMessage());
        showHelp(options);
        return;
    }

    // general options

    String[] extras = cmd.getArgs();

    if (cmd.hasOption(help.getOpt()) || extras.length < 2) {
        showHelp(options);
        return;
    }
    if (cmd.hasOption(verbose.getOpt())) {
        verbosity = Verbose;
    }
    if (cmd.hasOption(quiet.getOpt())) {
        verbosity = Quiet;
    }

    // import

    String source = extras[0];

    // optional import step
    if (cmd.hasOption(legacy.getOpt())) {
        String[] values = cmd.getOptionValues(legacy.getOpt());

        AdventureConverter converter = new AdventureConverter();
        if (values.length > 0 && values[0].equalsIgnoreCase("true")) {
            converter.setEnableSimplifications(true);
        }
        if (values.length > 1 && values[1].equalsIgnoreCase("true")) {
            converter.setEnableTranslations(true);
        }

        // set source for next steps to import-target
        source = converter.convert(source, null);
    }

    if (cmd.hasOption(jar.getOpt())) {
        if (checkFilesExist(cmd, options, source)) {
            JarExporter e = new JarExporter();
            e.export(source, extras[1], verbosity.equals(Quiet) ? new QuietStream() : System.err);
        }
    } else if (cmd.hasOption(apk.getOpt())) {
        String[] values = cmd.getOptionValues(apk.getOpt());
        if (checkFilesExist(cmd, options, values[0], values[1], source)) {
            AndroidExporter e = new AndroidExporter();
            Properties props = new Properties();
            File propsFile = new File(values[0]);
            try {
                props.load(new FileReader(propsFile));
                props.setProperty(AndroidExporter.SDK_HOME,
                        props.getProperty(AndroidExporter.SDK_HOME, values[1]));
            } catch (IOException ioe) {
                System.err.println("Could not load properties from " + propsFile.getAbsolutePath());
                return;
            }
            e.export(source, extras[1], props, values.length > 2 && values[2].equalsIgnoreCase("true"));
        }
    } else if (cmd.hasOption(war.getOpt())) {
        if (checkFilesExist(cmd, options, extras[0])) {
            WarExporter e = new WarExporter();
            e.setWarPath(cmd.getOptionValue(war.getOpt()));
            e.export(source, extras[1]);
        }
    } else if (cmd.hasOption(ead.getOpt())) {
        String destiny = extras[1];
        if (!destiny.endsWith(".ead")) {
            destiny += ".ead";
        }
        FileUtils.zip(new File(destiny), new File(source));
    } else {
        showHelp(options);
    }
}

From source file:com.github.braully.graph.UtilResultMerge.java

public static void main(String... args) throws Exception {
    Options options = new Options();

    Option input = new Option("i", "input", true, "input file path");
    input.setRequired(false);//  w  w  w  . jav a2s . co  m
    options.addOption(input);

    Option output = new Option("o", "output", true, "output file");
    output.setRequired(false);
    options.addOption(output);

    Option verb = new Option("v", "verbose", false, "verbose");
    output.setRequired(false);
    options.addOption(verb);

    Option exluces = new Option("x", "exclude", true, "exclude operations");
    exluces.setRequired(false);
    options.addOption(exluces);

    CommandLineParser parser = new DefaultParser();
    HelpFormatter formatter = new HelpFormatter();
    CommandLine cmd;

    try {
        cmd = parser.parse(options, args);
    } catch (ParseException e) {
        System.out.println(e.getMessage());
        formatter.printHelp("UtilResult", options);

        System.exit(1);
        return;
    }

    String[] excludes = cmd.getOptionValues("exclude");
    String[] inputs = cmd.getOptionValues("input");
    if (inputs == null) {
        inputs = new String[] {
                "/home/strike/Dropbox/workspace/graph-caratheodory-np3/grafos-processamento/Almost_hypohamiltonian"
                //                "/media/dados/documentos/grafos-processamento/Almost_hypohamiltonian",
                //                "/home/strike/Documentos/grafos-processamento/Cubic",
                //                "/home/strike/Documentos/grafos-processamento/Critical_H-free",
                //                "/home/strike/Documentos/grafos-processamento/Highly_irregular",
                //                "/home/strike/Documentos/grafos-processamento/Hypohamiltonian_graphs",
                //                "/home/strike/Documentos/grafos-processamento/Maximal_triangle-free",
                //                "/home/strike/Documentos/grafos-processamento/Minimal_Ramsey",
                //                "/home/strike/Documentos/grafos-processamento/Strongly_regular",
                //                "/home/strike/Documentos/grafos-processamento/Vertex-transitive",
                //                "/home/strike/Documentos/grafos-processamento/Trees"
        };
        excludes = new String[] { "carathe" };
        verbose = true;
    }

    if (cmd.hasOption(verb.getOpt())) {
        verbose = true;
    }

    if (inputs != null) {
        processInputs(inputs, excludes);
    }
}

From source file:com.example.dlp.Inspect.java

/**
 * Command line application to inspect data using the Data Loss Prevention API.
 * Supported data formats: string, file, text file on GCS, BigQuery table, and Datastore entity
 *//*from  w  ww  .  j a  v a  2  s  .  c  om*/
public static void main(String[] args) throws Exception {

    OptionGroup optionsGroup = new OptionGroup();
    optionsGroup.setRequired(true);
    Option stringOption = new Option("s", "string", true, "inspect string");
    optionsGroup.addOption(stringOption);

    Option fileOption = new Option("f", "file path", true, "inspect input file path");
    optionsGroup.addOption(fileOption);

    Option gcsOption = new Option("gcs", "Google Cloud Storage", false, "inspect GCS file");
    optionsGroup.addOption(gcsOption);

    Option datastoreOption = new Option("ds", "Google Datastore", false, "inspect Datastore kind");
    optionsGroup.addOption(datastoreOption);

    Option bigqueryOption = new Option("bq", "Google BigQuery", false, "inspect BigQuery table");
    optionsGroup.addOption(bigqueryOption);

    Options commandLineOptions = new Options();
    commandLineOptions.addOptionGroup(optionsGroup);

    Option minLikelihoodOption = Option.builder("minLikelihood").hasArg(true).required(false).build();

    commandLineOptions.addOption(minLikelihoodOption);

    Option maxFindingsOption = Option.builder("maxFindings").hasArg(true).required(false).build();

    commandLineOptions.addOption(maxFindingsOption);

    Option infoTypesOption = Option.builder("infoTypes").hasArg(true).required(false).build();
    infoTypesOption.setArgs(Option.UNLIMITED_VALUES);
    commandLineOptions.addOption(infoTypesOption);

    Option includeQuoteOption = Option.builder("includeQuote").hasArg(true).required(false).build();
    commandLineOptions.addOption(includeQuoteOption);

    Option bucketNameOption = Option.builder("bucketName").hasArg(true).required(false).build();
    commandLineOptions.addOption(bucketNameOption);

    Option gcsFileNameOption = Option.builder("fileName").hasArg(true).required(false).build();
    commandLineOptions.addOption(gcsFileNameOption);

    Option datasetIdOption = Option.builder("datasetId").hasArg(true).required(false).build();
    commandLineOptions.addOption(datasetIdOption);

    Option tableIdOption = Option.builder("tableId").hasArg(true).required(false).build();
    commandLineOptions.addOption(tableIdOption);

    Option projectIdOption = Option.builder("projectId").hasArg(true).required(false).build();
    commandLineOptions.addOption(projectIdOption);

    Option datastoreNamespaceOption = Option.builder("namespace").hasArg(true).required(false).build();
    commandLineOptions.addOption(datastoreNamespaceOption);

    Option datastoreKindOption = Option.builder("kind").hasArg(true).required(false).build();
    commandLineOptions.addOption(datastoreKindOption);

    CommandLineParser parser = new DefaultParser();
    HelpFormatter formatter = new HelpFormatter();
    CommandLine cmd;

    try {
        cmd = parser.parse(commandLineOptions, args);
    } catch (ParseException e) {
        System.out.println(e.getMessage());
        formatter.printHelp(Inspect.class.getName(), commandLineOptions);
        System.exit(1);
        return;
    }

    Likelihood minLikelihood = Likelihood.valueOf(
            cmd.getOptionValue(minLikelihoodOption.getOpt(), Likelihood.LIKELIHOOD_UNSPECIFIED.name()));
    int maxFindings = Integer.parseInt(cmd.getOptionValue(maxFindingsOption.getOpt(), "0"));
    boolean includeQuote = Boolean.parseBoolean(cmd.getOptionValue(includeQuoteOption.getOpt(), "true"));

    List<InfoType> infoTypesList = Collections.emptyList();
    if (cmd.hasOption(infoTypesOption.getOpt())) {
        infoTypesList = new ArrayList<>();
        String[] infoTypes = cmd.getOptionValues(infoTypesOption.getOpt());
        for (String infoType : infoTypes) {
            infoTypesList.add(InfoType.newBuilder().setName(infoType).build());
        }
    }
    // string inspection
    if (cmd.hasOption("s")) {
        String val = cmd.getOptionValue(stringOption.getOpt());
        inspectString(val, minLikelihood, maxFindings, infoTypesList, includeQuote);
    } else if (cmd.hasOption("f")) {
        String filePath = cmd.getOptionValue(fileOption.getOpt());
        inspectFile(filePath, minLikelihood, maxFindings, infoTypesList, includeQuote);
        // gcs file inspection
    } else if (cmd.hasOption("gcs")) {
        String bucketName = cmd.getOptionValue(bucketNameOption.getOpt());
        String fileName = cmd.getOptionValue(gcsFileNameOption.getOpt());
        inspectGcsFile(bucketName, fileName, minLikelihood, infoTypesList);
        // datastore kind inspection
    } else if (cmd.hasOption("ds")) {
        String namespaceId = cmd.getOptionValue(datastoreNamespaceOption.getOpt(), "");
        String kind = cmd.getOptionValue(datastoreKindOption.getOpt());
        // use default project id when project id is not specified
        String projectId = cmd.getOptionValue(projectIdOption.getOpt(), ServiceOptions.getDefaultProjectId());
        inspectDatastore(projectId, namespaceId, kind, minLikelihood, infoTypesList);
    } else if (cmd.hasOption("bq")) {
        String datasetId = cmd.getOptionValue(datasetIdOption.getOpt());
        String tableId = cmd.getOptionValue(tableIdOption.getOpt());
        // use default project id when project id is not specified
        String projectId = cmd.getOptionValue(projectIdOption.getOpt(), ServiceOptions.getDefaultProjectId());
        inspectBigquery(projectId, datasetId, tableId, minLikelihood, infoTypesList);
    }
}

From source file:com.ibm.crail.tools.CrailBenchmark.java

public static void main(String[] args) throws Exception {
    String type = "";
    String filename = "/tmp.dat";
    int size = CrailConstants.BUFFER_SIZE;
    int loop = 1;
    int batch = 1;
    int warmup = 32;
    int experiments = 1;
    boolean keepOpen = false;
    int storageClass = 0;
    int locationClass = 0;
    boolean useBuffered = true;

    String benchmarkTypes = "write|writeAsync|readSequential|readRandom|readSequentialAsync|readMultiStream|"
            + "createFile|createFileAsync|createMultiFile|getKey|getFile|getFileAsync|enumerateDir|browseDir|"
            + "writeInt|readInt|seekInt|readMultiStreamInt|printLocationclass";
    Option typeOption = Option.builder("t").desc("type of experiment [" + benchmarkTypes + "]").hasArg()
            .build();/* w  w  w .  j av  a 2 s. c o  m*/
    Option fileOption = Option.builder("f").desc("filename").hasArg().build();
    Option sizeOption = Option.builder("s").desc("buffer size [bytes]").hasArg().build();
    Option loopOption = Option.builder("k").desc("loop [1..n]").hasArg().build();
    Option batchOption = Option.builder("b").desc("batch size [1..n]").hasArg().build();
    Option storageOption = Option.builder("c").desc("storageClass for file [1..n]").hasArg().build();
    Option locationOption = Option.builder("p").desc("locationClass for file [1..n]").hasArg().build();
    Option warmupOption = Option.builder("w").desc("number of warmup operations [1..n]").hasArg().build();
    Option experimentOption = Option.builder("e").desc("number of experiments [1..n]").hasArg().build();
    Option openOption = Option.builder("o").desc("whether to keep the file system open [true|false]").hasArg()
            .build();
    Option bufferedOption = Option.builder("m").desc("use buffer streams [true|false]").hasArg().build();

    Options options = new Options();
    options.addOption(typeOption);
    options.addOption(fileOption);
    options.addOption(sizeOption);
    options.addOption(loopOption);
    options.addOption(batchOption);
    options.addOption(storageOption);
    options.addOption(locationOption);
    options.addOption(warmupOption);
    options.addOption(experimentOption);
    options.addOption(openOption);
    options.addOption(bufferedOption);

    CommandLineParser parser = new DefaultParser();
    CommandLine line = parser.parse(options, Arrays.copyOfRange(args, 0, args.length));
    if (line.hasOption(typeOption.getOpt())) {
        type = line.getOptionValue(typeOption.getOpt());
    }
    if (line.hasOption(fileOption.getOpt())) {
        filename = line.getOptionValue(fileOption.getOpt());
    }
    if (line.hasOption(sizeOption.getOpt())) {
        size = Integer.parseInt(line.getOptionValue(sizeOption.getOpt()));
    }
    if (line.hasOption(loopOption.getOpt())) {
        loop = Integer.parseInt(line.getOptionValue(loopOption.getOpt()));
    }
    if (line.hasOption(batchOption.getOpt())) {
        batch = Integer.parseInt(line.getOptionValue(batchOption.getOpt()));
    }
    if (line.hasOption(storageOption.getOpt())) {
        storageClass = Integer.parseInt(line.getOptionValue(storageOption.getOpt()));
    }
    if (line.hasOption(locationOption.getOpt())) {
        locationClass = Integer.parseInt(line.getOptionValue(locationOption.getOpt()));
    }
    if (line.hasOption(warmupOption.getOpt())) {
        warmup = Integer.parseInt(line.getOptionValue(warmupOption.getOpt()));
    }
    if (line.hasOption(experimentOption.getOpt())) {
        experiments = Integer.parseInt(line.getOptionValue(experimentOption.getOpt()));
    }
    if (line.hasOption(openOption.getOpt())) {
        keepOpen = Boolean.parseBoolean(line.getOptionValue(openOption.getOpt()));
    }
    if (line.hasOption(bufferedOption.getOpt())) {
        useBuffered = Boolean.parseBoolean(line.getOptionValue(bufferedOption.getOpt()));
    }

    CrailBenchmark benchmark = new CrailBenchmark(warmup);
    if (type.equals("write")) {
        benchmark.open();
        benchmark.write(filename, size, loop, storageClass, locationClass, useBuffered);
        benchmark.close();
    } else if (type.equalsIgnoreCase("writeAsync")) {
        benchmark.open();
        benchmark.writeAsync(filename, size, loop, batch, storageClass, locationClass);
        benchmark.close();
    } else if (type.equalsIgnoreCase("readSequential")) {
        if (keepOpen)
            benchmark.open();
        for (int i = 0; i < experiments; i++) {
            System.out.println("experiment " + i);
            if (!keepOpen)
                benchmark.open();
            benchmark.readSequential(filename, size, loop, useBuffered);
            if (!keepOpen)
                benchmark.close();
        }
        if (keepOpen)
            benchmark.close();
    } else if (type.equals("readRandom")) {
        if (keepOpen)
            benchmark.open();
        for (int i = 0; i < experiments; i++) {
            System.out.println("experiment " + i);
            if (!keepOpen)
                benchmark.open();
            benchmark.readRandom(filename, size, loop, useBuffered);
            if (!keepOpen)
                benchmark.close();
        }
        if (keepOpen)
            benchmark.close();
    } else if (type.equalsIgnoreCase("readSequentialAsync")) {
        if (keepOpen)
            benchmark.open();
        for (int i = 0; i < experiments; i++) {
            System.out.println("experiment " + i);
            if (!keepOpen)
                benchmark.open();
            benchmark.readSequentialAsync(filename, size, loop, batch);
            if (!keepOpen)
                benchmark.close();
        }
        if (keepOpen)
            benchmark.close();
    } else if (type.equalsIgnoreCase("readMultiStream")) {
        if (keepOpen)
            benchmark.open();
        for (int i = 0; i < experiments; i++) {
            System.out.println("experiment " + i);
            if (!keepOpen)
                benchmark.open();
            benchmark.readMultiStream(filename, size, loop, batch);
            if (!keepOpen)
                benchmark.close();
        }
        if (keepOpen)
            benchmark.close();
    } else if (type.equals("createFile")) {
        benchmark.open();
        benchmark.createFile(filename, loop);
        benchmark.close();
    } else if (type.equals("createFileAsync")) {
        benchmark.open();
        benchmark.createFileAsync(filename, loop, batch);
        benchmark.close();
    } else if (type.equalsIgnoreCase("createMultiFile")) {
        benchmark.open();
        benchmark.createMultiFile(filename, storageClass);
        benchmark.close();
    } else if (type.equalsIgnoreCase("getKey")) {
        benchmark.open();
        benchmark.getKey(filename, size, loop);
        benchmark.close();
    } else if (type.equals("getFile")) {
        benchmark.open();
        benchmark.getFile(filename, loop);
        benchmark.close();
    } else if (type.equals("getFileAsync")) {
        benchmark.open();
        benchmark.getFileAsync(filename, loop, batch);
        benchmark.close();
    } else if (type.equalsIgnoreCase("enumerateDir")) {
        benchmark.open();
        benchmark.enumerateDir(filename, batch);
        benchmark.close();
    } else if (type.equalsIgnoreCase("browseDir")) {
        benchmark.open();
        benchmark.browseDir(filename);
        benchmark.close();
    } else if (type.equalsIgnoreCase("early")) {
        benchmark.open();
        benchmark.early(filename);
        benchmark.close();
    } else if (type.equalsIgnoreCase("writeInt")) {
        benchmark.open();
        benchmark.writeInt(filename, loop);
        benchmark.close();
    } else if (type.equalsIgnoreCase("readInt")) {
        benchmark.open();
        benchmark.readInt(filename, loop);
        benchmark.close();
    } else if (type.equalsIgnoreCase("seekInt")) {
        benchmark.open();
        benchmark.seekInt(filename, loop);
        benchmark.close();
    } else if (type.equalsIgnoreCase("readMultiStreamInt")) {
        benchmark.open();
        benchmark.readMultiStreamInt(filename, loop, batch);
        benchmark.close();
    } else if (type.equalsIgnoreCase("printLocationClass")) {
        benchmark.open();
        benchmark.printLocationClass();
        benchmark.close();
    } else if (type.equalsIgnoreCase("collection")) {
        for (int i = 0; i < experiments; i++) {
            benchmark.collectionTest(size, loop);
        }
    } else if (type.equalsIgnoreCase("locationMap")) {
        benchmark.locationMap();
    } else {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("crail iobench", options);
        System.exit(-1);
    }
}

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

/**
 * @param args//from   www . j av a 2 s .c  o  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:be.dnsbelgium.rdap.client.ManGenerator.java

private static String getOptionString(Option option) {
    return String.format("%s%s%s", option.getOpt() == null ? "" : "-" + option.getOpt() + " ",
            option.getLongOpt() == null ? "" : "--" + option.getLongOpt() + " ",
            option.hasArg() ? "<" + option.getArgName() + ">" : ""

    ).trim();/*from   w w w .  j a  v a 2 s  .  c o m*/
}

From source file:de.topobyte.utilities.apache.commons.cli.OptionUtil.java

/**
 * This method provides the same functionality as the {@link Option}'s
 * {@code getKey()} method, which has package private visibility however. It
 * returns {@link Option#getOpt()} if the return value of that method is
 * non-null and {@link Option#getLongOpt()} otherwise.
 * //from   w  w w .j av  a2 s .  c o  m
 * @param option
 *            the option to get the key for.
 */
public static String getKey(Option option) {
    String opt = option.getOpt();
    return opt != null ? opt : option.getLongOpt();
}

From source file:com.ning.hfind.primary.PrimaryFactory.java

public static Primary primaryFromOption(Option o) throws MalformedPatternException {
    String primaryString = o.getOpt();
    String argument = o.getValue();
    return getPrimary(primaryString, argument);
}

From source file:edu.indiana.d2i.htrc.test.TestSuite.java

public static void testCommandLineParser(String[] args) throws IOException {
    GenericOptionsParser parser = new GenericOptionsParser(new Configuration(), args);

    CommandLine commandLine = parser.getCommandLine();

    Option[] options = commandLine.getOptions();

    for (Option op : options) {
        System.out.println(String.format("optName=%s, optValue=%s", op.getOpt(), op.getValue()));
    }/*from   w ww . j ava2s .  c o  m*/

    // second application argument is the output folder prefix
    String[] appArgs = parser.getRemainingArgs();

    for (String appArg : appArgs) {
        System.out.println(String.format("appArg=%s", appArg));
    }

    int iterationNum = 0;

    String[] arguments = LDAAnalysisDriver.generateArgs(options, new String[0], appArgs[0],
            appArgs[1] + "-iter-" + iterationNum);

    System.out.println("Passed in arguments in the first iteration");
    for (String arg : arguments) {
        System.out.println(String.format("argument=%s", arg));
    }

    String[] otherOps = { "-D", "user.args.lda.state.filepath=" + appArgs[1] + "-iter-" + iterationNum
            + File.separator + "part-r-00000" };

    arguments = LDAAnalysisDriver.generateArgs(options, otherOps, appArgs[0],
            appArgs[1] + "-iter-" + ++iterationNum);

    System.out.println("Passed in arguments in the second iteration");
    for (String arg : arguments) {
        System.out.println(String.format("argument=%s", arg));
    }
}

From source file:de.mustnotbenamed.quickstart.undertowserver.CliHelper.java

public static <T> T option(CommandLine cmd, Option option, T defaultValue) throws ParseException {
    T result = defaultValue;//from w w w .  jav  a2  s .c  o  m

    if (cmd.hasOption(option.getOpt())) {
        String optionValue = cmd.getOptionValue(option.getOpt());
        result = (T) TypeHandler.createValue(optionValue, option.getType());
    }

    return result;
}