Example usage for org.apache.commons.cli Options getOption

List of usage examples for org.apache.commons.cli Options getOption

Introduction

In this page you can find the example usage for org.apache.commons.cli Options getOption.

Prototype

public Option getOption(String opt) 

Source Link

Document

Retrieve the Option matching the long or short name specified.

Usage

From source file:net.sourceforge.dita4publishers.tools.mapreporter.MapBosReporter.java

/**
 * @return//from w  w w.jav a 2  s .c  o  m
 */
protected static Options configureOptions() {
    Options options = configureOptionsBase();
    Option opt = null;

    options.addOption(INPUT_OPTION_ONE_CHAR, "map", true,
            "(Input) The root map from which to calculate the map tree or bounded object set");
    opt = options.getOption(INPUT_OPTION_ONE_CHAR);
    opt.setRequired(true);

    options.addOption(OUTPUT_OPTION_ONE_CHAR, "out", true,
            "(Output) The name of the output directory and, optionally, report file to generate.  "
                    + "If not specified, output goes to STDOUT.");
    opt = options.getOption(OUTPUT_OPTION_ONE_CHAR);
    opt.setRequired(false);

    options.addOption(CATALOG_OPTION_ONE_CHAR, "catalog", true,
            "(Catalog) Path and filename of the XML catalog to use for resolving DTDs (e.g., catalog-dita.xml)");
    opt = options.getOption(OUTPUT_OPTION_ONE_CHAR);
    opt.setRequired(false);

    options.addOption(DITAVAL_OPTION_ONE_CHAR, "ditaval", true,
            "(Ditaval) Path and filename of the the Ditaval file to used to determine applicable key definitions and other elements.");
    opt = options.getOption(DITAVAL_OPTION_ONE_CHAR);
    opt.setRequired(false);

    options.addOption(BOS_REPORTER_CLASS_OPTION_ONE_CHAR, "bosreporterclass", true,
            "(BOS reporter class) Fully-qualified class name of the BOS reporter to use. "
                    + "If not specified, the built-in text BOS reporter is used.");
    opt = options.getOption(BOS_REPORTER_CLASS_OPTION_ONE_CHAR);
    opt.setRequired(false);

    options.addOption(KEYSPACE_REPORTER_CLASS_OPTION_ONE_CHAR, "keyspacereporterclass", true,
            "(Key space reporter class) Fully-qualified class name of the key space reporter to use."
                    + " If not specified, the built-in text key space reporter is used.");
    opt = options.getOption(KEYSPACE_REPORTER_CLASS_OPTION_ONE_CHAR);
    opt.setRequired(false);

    options.addOption(MAPTREE_OPTION_ONE_CHAR, "maptree", false,
            "(Map tree only) When specified, only calculates the map tree, not the entire DITA BOS.");
    opt = options.getOption(OUTPUT_OPTION_ONE_CHAR);
    opt.setRequired(false);

    return options;
}

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

/**
 * Helper method that throws a {@link ParseException} if parameter arguments are missing.
 * /*from   w  ww .ja  v  a 2 s . co m*/
 * @param cmd the concrete {@link CommandLine}
 * @param param name of the parameter that is to be validated
 * @param opts configured {@link Options}
 * @throws ParseException if the number of arguments does not correspond to the expected number of arguments for the given parameter
 */
public static void validateNumberOfArguments(CommandLine cmd, char param, Options opts) throws ParseException {
    Integer numberOfArgs = param2arguments.get(param);
    String[] tmp = cmd.getOptionValues(param);
    if (numberOfArgs != null && tmp != null && tmp.length % numberOfArgs != 0) {
        Option o = opts.getOption(Character.toString(param));
        String name = o.getLongOpt() != null ? o.getLongOpt() : Character.toString(param);
        throw new ParseException("Invalid amount of arguments for parameter " + name + ": <" + o.getArgName()
                + ">. Description: " + o.getDescription());
    }
}

From source file:heybot.heybot.java

private static Options buildOptions() {
    Options options = new Options();

    options.addOption("d", "do", true, "Heybot operation file with .hb extension." + NEWLINE + "something.hb");
    options.getOption("do").setRequired(true);

    options.addOption("h", "help", false, "Prints this help message.");
    options.addOption("v", "version", false, "Prints detailed version information.");
    options.addOption("l", "list", false, "Lists all operation files in workspace.");
    options.addOption("lp", "list-prefix", true,
            "Lists operation files in workspace which starts with given value.");
    options.addOption("i", "insert", true,
            "Inserts (by replacing if exists) given parameter values of an operation.");
    options.addOption("s", "select", true, "Selects all parameters with values of an operation");
    options.addOption("o", "open", true,
            "Opens operation file in editor defined in HEYBOT_EDITOR environment variable.");
    options.addOption("r", "remove", true, "Removes operation file from workspace.");

    return options;
}

From source file:edu.usc.squash.Main.java

private static boolean parseInputs(String[] args) {
    Options options = new Options();

    options.addOption("k", "cores", true, "Total number of cores (Default: " + k + ")");
    options.getOption("k").setArgName("number");

    options.addOption("p", "physical", true,
            "Physical ancilla budget (Default: " + physicalAncillaBudget + ")");
    options.getOption("p").setArgName("number");

    options.addOption("b", "beta_pmd", true, "Beta_PMD (Default: " + beta_pmd + ")");
    options.getOption("b").setArgName("number");

    options.addOption("a", "alpha_int", true, "Alpha_int (Default: " + alpha_int + ")");
    options.getOption("a").setArgName("number");

    options.addOption("g", "gamma_mem", true, "Gamma_memory (Default: " + gamma_memory + ")");
    options.getOption("g").setArgName("number");

    options.addOption("e", "ecc", true, "Error correcting code (Default: " + currentECC + ")");
    options.getOption("e").setArgName("type");

    options.addOption("q", "hf-qasm", true, "HF-QASM input file");
    options.getOption("q").setArgName("file");

    options.addOption("l", "lib", true, "Library file");
    options.getOption("l").setArgName("file");

    options.addOption("m", "metis", true, "Metis directory (Default: " + metisDir + ")");
    options.getOption("m").setArgName("path");

    options.addOption("t", "timeout", true, "Gurobi timelimit for binding (Default: " + gurobiTimeLimit + "s)");
    options.getOption("t").setArgName("number");

    options.addOption("h", "help", false, "Shows this help menu");

    CommandLineParser parser = new GnuParser();
    CommandLine cmd = null;//from  w ww  . j  a  v  a 2s . c om
    try {
        cmd = parser.parse(options, args);
    } catch (ParseException e) {
        System.err.println(e.getMessage());
        System.exit(-1);
    }

    if (!cmd.hasOption("lib") || !cmd.hasOption("hf-qasm") || cmd.hasOption("help")) {
        //TODO: remove this
        if (libraryPath == null || hfqPath == null || cmd.hasOption("help")) {
            print_usage(options);
            return false;
        }
    }

    if (cmd.hasOption("lib")) {
        libraryPath = cmd.getOptionValue("lib");
        if (!new File(libraryPath).exists()) {
            System.err.println("Library file " + hfqPath + " does not exist.");
            return false;
        }
    }

    if (cmd.hasOption("hf-qasm")) {
        hfqPath = cmd.getOptionValue("hf-qasm");
        if (!new File(hfqPath).exists()) {
            System.err.println("HF-QASM file " + hfqPath + " does not exist.");
            return false;
        }
    }

    if (cmd.hasOption("cores")) {
        k = Integer.parseInt(cmd.getOptionValue("cores"));
    }

    if (cmd.hasOption("timelimit")) {
        gurobiTimeLimit = Integer.parseInt(cmd.getOptionValue("timelimit"));
    }

    if (cmd.hasOption("physical")) {
        physicalAncillaBudget = Integer.parseInt(cmd.getOptionValue("physical"));
    }

    if (cmd.hasOption("beta_pmd")) {
        beta_pmd = Integer.parseInt(cmd.getOptionValue("beta_pmd"));
    }

    if (cmd.hasOption("alpha_int")) {
        alpha_int = Integer.parseInt(cmd.getOptionValue("alpha_int"));
    }

    if (cmd.hasOption("gamma_memory")) {
        gamma_memory = Integer.parseInt(cmd.getOptionValue("gamma_memory"));
    }
    if (cmd.hasOption("ecc")) {
        currentECC = cmd.getOptionValue("ecc");
    }

    if (cmd.hasOption("metis")) {
        metisDir = cmd.getOptionValue("metis");
    }

    return true;
}

From source file:de.zib.scalaris.Main.java

/**
 * Checks that the given option value as returned from e.g.
 * {@link CommandLine#getOptionValue(String)} does exist and prints an error
 * message if not./*from w  ww  .  j  a v  a 2 s  .c  o  m*/
 * 
 * @param optionValue    the value to check
 * @param options        the available command line options
 * @param currentOption  the short name of the current option being parsed
 */
private final static void checkArguments(String optionValue, Options options, String currentOption) {
    if (optionValue == null) {
        printException("Parsing failed", new ParseException("missing parameter for option " + currentOption
                + " (required: <" + options.getOption(currentOption).getArgName() + ">)"), false);
    }
}

From source file:co.cask.cdap.cli.CLIMainArgs.java

public static CLIMainArgs parse(String[] args, Options options) {
    List<String> optionsPart = Lists.newArrayList();
    List<String> commandPart = Lists.newArrayList();

    boolean inOptionsPart = true;
    for (int i = 0; i < args.length; i++) {
        String token = args[i];//from   w  w  w.  j  a v a  2  s.  c  o m
        if (inOptionsPart) {
            if (!token.startsWith("-")) {
                inOptionsPart = false;
            } else if (!options.hasOption(token)) {
                inOptionsPart = true;
            } else if (!options.getOption(token).hasArg()) {
                inOptionsPart = true;
            } else if (options.getOption(token).hasArg() && i + 1 < args.length) {
                inOptionsPart = true;
                // add the option and option value
                optionsPart.add(token);
                optionsPart.add(args[++i]);
                continue;
            } else {
                inOptionsPart = false;
            }
        }

        if (inOptionsPart) {
            optionsPart.add(token);
        } else {
            commandPart.add(token);
        }
    }
    return new CLIMainArgs(optionsPart.toArray(new String[optionsPart.size()]),
            commandPart.toArray(new String[commandPart.size()]));
}

From source file:de.zib.scalaris.Main.java

/**
 * Checks that the given option values as returned from e.g.
 * {@link CommandLine#getOptionValues(String)} does exist and contains
 * enough parameters. Prints an error message if not.
 * //from w  w  w  .  ja v a2 s  . c  om
 * @param optionValues   the values to check
 * @param required       the number of required parameters
 * @param options        the available command line options
 * @param currentOption  the short name of the current option being parsed
 */
private final static void checkArguments(String[] optionValues, int required, Options options,
        String currentOption) {
    if (optionValues == null || optionValues.length < required) {
        printException("Parsing failed", new ParseException("missing parameter for option " + currentOption
                + " (required: <" + options.getOption(currentOption).getArgName() + ">)"), false);
    }
}

From source file:com.somerledsolutions.pa11y.client.cli.OptionsBuilderTest.java

private void assertHelpOption(Options options) {
    Option helpOption = options.getOption("h");
    assertEquals("h", helpOption.getOpt());
    assertEquals("Help", helpOption.getArgName());
    assertEquals("help", helpOption.getLongOpt());
    assertEquals("Shows this help", helpOption.getDescription());
}

From source file:com.somerledsolutions.pa11y.client.cli.OptionsBuilderTest.java

private void assertCreateOption(Options options) {
    Option createOption = options.getOption("c");
    assertEquals("c", createOption.getOpt());
    assertEquals("Create task", createOption.getArgName());
    assertEquals("create", createOption.getLongOpt());
    assertEquals("Create a new task", createOption.getDescription());
}

From source file:com.somerledsolutions.pa11y.client.cli.OptionsBuilderTest.java

private void assertListTasksOption(Options options) {
    Option createOption = options.getOption("l");
    assertEquals("l", createOption.getOpt());
    assertEquals("List all tasks", createOption.getArgName());
    assertEquals("list", createOption.getLongOpt());
    assertEquals("Get all of the tasks in the application", createOption.getDescription());
}