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

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

Introduction

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

Prototype

public void setRequired(boolean required) 

Source Link

Document

Sets whether this Option is mandatory.

Usage

From source file:edu.sdsc.scigraph.owlapi.loader.BatchOwlLoader.java

protected static Options getOptions() {
    Option configPath = new Option("c", "configpath", true, "The location of the configuration file");
    configPath.setRequired(true);
    Options options = new Options();
    options.addOption(configPath);// ww  w .j av  a 2  s .c  o m
    return options;
}

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

/**
 * Add a long option to the options specified by parameters
 * /* w w  w.  j  av  a2 s.  com*/
 * @param options
 *            the options to add to.
 * @param longName
 *            the long option name.
 * @param hasArg
 *            whether it expects an argument
 * @param required
 *            whether this is a required option.
 * @param argName
 *            the name of the argument.
 * @param description
 *            the option description
 * @return the Option object created.
 */
public static Option addL(Options options, String longName, boolean hasArg, boolean required, String argName,
        String description) {
    Option option = new Option(null, longName, hasArg, description);
    option.setRequired(required);
    option.setArgName(argName);
    options.addOption(option);
    return option;
}

From source file:net.sf.markov4jmeter.behaviormodelextractor.CmdlOptionFactory.java

/**
 * Creates an option with a specified number of arguments;
 *
 * @param opt/*from w  ww .j a va 2s  . c o  m*/
 *     Short representation of the option (e.g. <code>"s"</code>).
 * @param longOpt
 *     Long representation of the option
 *     (e.g. <code>"source-project"</code>).
 * @param description
 *     Description of the option
 *     (e.g. <code>"Path to source project."</code>).
 * @param isRequired
 *     Flag indicating whether the option is required (as a command-line
 *     argument) or not.
 * @param argName
 *     Display name for the argument value.
 * @param argsNum
 *     Number of arguments; a negative value indicates an infinite sequence
 *     of arguments.
 * @param hasOptionalArg
 *     <code>true</code> if and only if the arguments are optional.
 * @return
 *     An instance of {@link Option} with the specified properties.
 */
public static Option createOption(final String opt, final String longOpt, final String description,
        final boolean isRequired, final String argName, final int argsNum, final boolean hasOptionalArg) {

    final Option option = new Option(opt, longOpt, argsNum != 0 /* hasArg */, description);

    option.setRequired(isRequired);

    if (argsNum != 0) { // argsNum < 0 for infinite sequence of arguments;

        if (argName != null) {
            option.setArgName(argName);
        }
        // negative number of arguments implies an infinite sequence;
        option.setArgs((argsNum < 0) ? Integer.MAX_VALUE : argsNum);

        option.setValueSeparator(CmdlOptionFactory.DEFAULT_VALUE_SEPARATOR);
        option.setOptionalArg(hasOptionalArg);
    }
    return option;
}

From source file:Generate.java

private static void optionSetup() {
    options = new Options();

    Option help = new Option("h", "help", false, "print usage of Pyjama compiler");
    help.setRequired(false);
    options.addOption(help);// w  ww  . j  a v a2  s . com

    Option classpath = new Option("cp", "classpath", true,
            "Specify where to find user class files and annotation processors");
    classpath.setRequired(false);
    classpath.setArgs(1);
    classpath.setArgName("PATH");
    options.addOption(classpath);

    Option outputPath = new Option("d", "directory", true, "output file directory");
    outputPath.setRequired(false);
    outputPath.setArgs(1);
    outputPath.setArgName("DIR");
    options.addOption(outputPath);

    Option j2c = new Option("j2c", "javatoclass", false,
            "(default)compile .java file to paralleled .class file");
    j2c.setRequired(false);
    options.addOption(j2c);

    Option j2j = new Option("j2j", "javatojava", false,
            "compile .java file to paralleled .java file. "
                    + "Remember new parallel java file will overwrite old sequential java file, "
                    + "if there is no target directory is specified.");
    j2j.setRequired(false);
    options.addOption(j2j);

    Option p2c = new Option("p2c", "pjtoclass", false, "compile .pj file to paralleled .class file");
    p2c.setRequired(false);
    options.addOption(p2c);

    Option p2j = new Option("p2j", "pjtojava", false, "compile .pj file to paralleled .java file");
    p2j.setRequired(false);
    options.addOption(p2j);
}

From source file:edu.illinois.cs.cogcomp.datalessclassification.ta.ESADatalessAnnotator.java

public static CommandLine getCMDOpts(String[] args) {
    Options options = new Options();

    Option configOpt = new Option("c", "config", true, "config file path");
    configOpt.setRequired(false);
    options.addOption(configOpt);/*from   w w w .  j a v a2s  . co  m*/

    Option testFileOption = new Option("f", "testFile", true, "File to annotate using Dataless");
    testFileOption.setRequired(false);
    options.addOption(testFileOption);

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

    CommandLine cmd = null;

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

        System.exit(1);
        return cmd;
    }

    return cmd;
}

From source file:de.gesundkrank.wikipedia.hadoop.util.RepackToMapFile.java

private static Options getOptions() {

    Options options = new Options();

    options.addOption("h", "help", false, "Show this message.");

    Option basePath = new Option("b", "basePath", true,
            "The path where your Wikipedia dumps get stored. " + "Creates subPaths.");
    basePath.setRequired(true);
    options.addOption(basePath);// w w w.  ja  v a  2  s  . co m

    Option outputPath = new Option("o", "outputPath", true, "Path where the MapFile is stored.");
    outputPath.setRequired(true);
    options.addOption(outputPath);

    options.addOption("c", "checkNew", false, "Checks for new Wikipedia online.");
    options.addOption("r", "skipRedirect", false, "Skip redirect pages when indexing");

    return options;
}

From source file:com.aliyun.openservices.odps.console.commands.ShowTablesCommand.java

static Options initOptions() {
    Options opts = new Options();
    Option project_name = new Option("p", "project", true, "project name");
    project_name.setRequired(false);

    opts.addOption(project_name);/*from w  w  w  .  java2 s.  c  om*/

    return opts;
}

From source file:com.genentech.chemistry.tool.SDFBinning.java

private static void processOptions(String[] args) {
    Options options = new Options();

    Option opt = new Option("in", true, "Input file oe-supported Use .sdf to specify the file type.");
    opt.setRequired(true);
    options.addOption(opt);//  w  w  w. j  a  va 2 s.c  om

    opt = new Option("out", true, "Output file oe-supported Use .sdf to specify the file type.");
    opt.setRequired(true);
    options.addOption(opt);

    opt = new Option("bin", true,
            "bin definition. Use format \"bin_1_upperbound=bin_1_name|bin_2_upperbound=bin_2_name|bin_3_upperbound_=bin_3_name\"");
    opt.setRequired(true);
    options.addOption(opt);

    opt = new Option("dataTag", true, "SD tag containing data for binning");
    opt.setRequired(true);
    options.addOption(opt);

    opt = new Option("binTag", true, "SD tag used for storing bin names");
    opt.setRequired(true);
    options.addOption(opt);

    opt = new Option("ignoreModifier", false, "ignore leading '><= ~'");
    options.addOption(opt);

    opt = new Option("h", false, "print usage statement");
    opt.setRequired(false);
    options.addOption(opt);

    PosixParser parser = new PosixParser();
    CommandLine cl = null;

    try {
        cl = parser.parse(options, args);
    } catch (Exception exp) {
        // catch (ParseException exp) {
        System.err.println(exp.getMessage());
        exitWithHelp(options);
    }
    inFile = cl.getOptionValue("in");
    outFile = cl.getOptionValue("out");
    ignoreModifier = cl.hasOption("ignoreModifier");
    String binDefinition = cl.getOptionValue("bin");
    parseBins(binDefinition);

    binTag = cl.getOptionValue("binTag");
    dataTag = cl.getOptionValue("dataTag");
}

From source file:com.yahoo.athenz.example.instance.InstanceClientRegister.java

private static CommandLine parseCommandLine(String[] args) {

    Options options = new Options();

    Option domain = new Option("d", "domain", true, "domain name");
    domain.setRequired(true);
    options.addOption(domain);/*from  www .  j  av  a 2 s  .c  o m*/

    Option service = new Option("s", "service", true, "service name");
    service.setRequired(true);
    options.addOption(service);

    Option provider = new Option("p", "provider", true, "provider name");
    provider.setRequired(true);
    options.addOption(provider);

    Option instance = new Option("i", "instance", true, "instance id");
    instance.setRequired(true);
    options.addOption(instance);

    Option dnsSuffix = new Option("dns", "dnssuffix", true, "provider dns suffix");
    dnsSuffix.setRequired(true);
    options.addOption(dnsSuffix);

    Option providerKey = new Option("pk", "providerkey", true, "provider private key path");
    providerKey.setRequired(true);
    options.addOption(providerKey);

    Option keyId = new Option("pkid", "providerkeyid", true, "provider private key identifier");
    keyId.setRequired(true);
    options.addOption(keyId);

    Option instanceKey = new Option("ik", "instancekey", true, "instance private key path");
    instanceKey.setRequired(true);
    options.addOption(instanceKey);

    Option ztsUrl = new Option("z", "ztsurl", true, "ZTS Server url");
    ztsUrl.setRequired(true);
    options.addOption(ztsUrl);

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

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

    return cmd;
}

From source file:ee.ria.xroad.proxy.opmonitoring.OpMonitoringBufferMemoryUsage.java

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

    Option count = new Option("c", "count", true, "records count (default: " + DEFAULT_COUNT + ")");
    count.setRequired(false);
    options.addOption(count);/*from  w  ww.jav a  2s. c o  m*/

    Option longStringLength = new Option("lsl", "long-string-length", true,
            "long string length (default: " + DEFAULT_LONG_STRING_LENGTH + ")");
    longStringLength.setRequired(false);
    options.addOption(longStringLength);

    Option shortStringLength = new Option("ssl", "short-string-length", true,
            "short string length (default: " + DEFAULT_SHORT_LONG_STRING_LENGTH + ")");
    shortStringLength.setRequired(false);
    options.addOption(shortStringLength);

    Option usage = new Option("h", "help", false, "help");
    usage.setRequired(false);
    options.addOption(usage);

    return options;
}