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:de.thomasvolk.genexample.GenAlg.java

private static Option option(String name, String descr) {
    Option opt = new Option(name, true, descr);
    opt.setRequired(false);
    return opt;/*from  w  w w . ja  v a 2  s  . c om*/
}

From source file:com.alibaba.rocketmq.example.operation.Consumer.java

public static CommandLine buildCommandline(String[] args) {
    final Options options = new Options();
    // ////////////////////////////////////////////////////
    Option opt = new Option("h", "help", false, "Print help");
    opt.setRequired(false);
    options.addOption(opt);//from ww w .  java2  s  . co m

    opt = new Option("g", "consumerGroup", true, "Consumer Group Name");
    opt.setRequired(true);
    options.addOption(opt);

    opt = new Option("t", "topic", true, "Topic Name");
    opt.setRequired(true);
    options.addOption(opt);

    opt = new Option("s", "subscription", true, "subscription");
    opt.setRequired(false);
    options.addOption(opt);

    opt = new Option("f", "returnFailedHalf", true, "return failed result, for half message");
    opt.setRequired(true);
    options.addOption(opt);

    // ////////////////////////////////////////////////////

    PosixParser parser = new PosixParser();
    HelpFormatter hf = new HelpFormatter();
    hf.setWidth(110);
    CommandLine commandLine = null;
    try {
        commandLine = parser.parse(options, args);
        if (commandLine.hasOption('h')) {
            hf.printHelp("producer", options, true);
            return null;
        }
    } catch (ParseException e) {
        hf.printHelp("producer", options, true);
        return null;
    }

    return commandLine;
}

From source file:com.alibaba.rocketmq.example.operation.Producer.java

public static CommandLine buildCommandline(String[] args) {
    final Options options = new Options();
    // ////////////////////////////////////////////////////
    Option opt = new Option("h", "help", false, "Print help");
    opt.setRequired(false);
    options.addOption(opt);// w w w .ja  va  2 s .c o m

    opt = new Option("g", "producerGroup", true, "Producer Group Name");
    opt.setRequired(true);
    options.addOption(opt);

    opt = new Option("t", "topic", true, "Topic Name");
    opt.setRequired(true);
    options.addOption(opt);

    opt = new Option("a", "tags", true, "Tags Name");
    opt.setRequired(true);
    options.addOption(opt);

    opt = new Option("k", "keys", true, "Keys Name");
    opt.setRequired(true);
    options.addOption(opt);

    opt = new Option("c", "msgCount", true, "Message Count");
    opt.setRequired(true);
    options.addOption(opt);

    // ////////////////////////////////////////////////////

    PosixParser parser = new PosixParser();
    HelpFormatter hf = new HelpFormatter();
    hf.setWidth(110);
    CommandLine commandLine = null;
    try {
        commandLine = parser.parse(options, args);
        if (commandLine.hasOption('h')) {
            hf.printHelp("producer", options, true);
            return null;
        }
    } catch (ParseException e) {
        hf.printHelp("producer", options, true);
        return null;
    }

    return commandLine;
}

From source file:com.ztesoft.zsmart.remoting.util.ServerUtil.java

public static Options buildCommandlineOptions(final Options options) {
    Option opt = new Option("h", "help", false, "Print help");
    opt.setRequired(false);
    options.addOption(opt);//from  w  w  w  .  ja v  a  2 s  .  c  om

    opt = new Option("n", "namesrvAddr", true, "Name server address list,eg:192.168.1.1:9876");
    opt.setRequired(true);
    options.addOption(opt);

    return options;
}

From source file:de.longri.cachebox3.DesktopLauncher.java

private static CommandLine getCommandLine(String[] args) {
    Options options = new Options();

    Option scale = new Option("s", "scale", true, "scale factor");
    scale.setRequired(false);
    options.addOption(scale);/*from  w w w.  j av  a 2s  .c  o m*/

    Option note4 = new Option("n", "note", false, "force layout for Note4");
    note4.setRequired(false);
    options.addOption(note4);

    Option gpsSimulator = new Option("g", "gps", false, "start with GPS simulator");
    gpsSimulator.setRequired(false);
    options.addOption(gpsSimulator);

    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("CacheBoxStarter", options);

        System.exit(1);
        return null;
    }
    return cmd;
}

From source file:com.yahoo.athenz.example.http.tls.client.HttpTLSClient.java

private static CommandLine parseCommandLine(String[] args) {

    Options options = new Options();

    Option key = new Option("k", "key", true, "private key path");
    key.setRequired(true);
    options.addOption(key);/*w ww  . j a v  a  2s  .c o  m*/

    Option cert = new Option("c", "cert", true, "certficate path");
    cert.setRequired(true);
    options.addOption(cert);

    Option trustStore = new Option("t", "trustStorePath", true, "CA TrustStore path");
    trustStore.setRequired(true);
    options.addOption(trustStore);

    Option trustStorePassword = new Option("p", "trustStorePassword", true, "CA TrustStore password");
    trustStorePassword.setRequired(true);
    options.addOption(trustStorePassword);

    Option ztsUrl = new Option("u", "url", true, "HTTP 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("zts-tls-client", options);
        System.exit(1);
    }

    return cmd;
}

From source file:hu.bme.mit.trainbenchmark.config.TrainBenchmarkConfig.java

protected static Option requiredOption(final String name, final String description) {
    final Option option = new Option(name, true, description);
    option.setRequired(true);
    return option;
}

From source file:com.yahoo.athenz.example.ntoken.HttpExampleClient.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   ww w. ja va 2s .c o  m

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

    Option privateKey = new Option("p", "pkey", true, "private key path");
    privateKey.setRequired(true);
    options.addOption(privateKey);

    Option keyId = new Option("k", "keyid", true, "key identifier");
    keyId.setRequired(true);
    options.addOption(keyId);

    Option url = new Option("u", "url", true, "request url");
    url.setRequired(true);
    options.addOption(url);

    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("http-example-client", options);
        System.exit(1);
    }

    return cmd;
}

From source file:info.bitoo.Main.java

private static Options createCommandLineOptions() {
    Option optConfig = new Option("c", "config", true, "configuration file location");

    Option optTorrent = new Option("t", "torrent", true, "a .torrent file to download");
    optTorrent.setRequired(true);

    Option optFile = new Option("f", "file", true, "a file to download on the specified tracker");
    optTorrent.setRequired(true);//w w  w. j a  v  a  2s  .c o m

    OptionGroup optionGroup = new OptionGroup();
    optionGroup.addOption(optTorrent).addOption(optFile);

    Options cliOptions = new Options();
    cliOptions.addOption(optConfig);
    cliOptions.addOptionGroup(optionGroup);

    return cliOptions;
}

From source file:com.aliyun.openservices.odps.console.resource.DropFunctionCommand.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);/*  www. j  a  va 2  s. c om*/
    return opts;
}