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:com.ibm.watson.app.common.tools.utils.CliUtils.java

public static Option createOption(String opt, String longOpt, boolean hasArg, String description,
        boolean required, String argName) {
    Option option = new Option(opt, longOpt, hasArg, description);
    option.setRequired(required);
    option.setArgName(argName);//from  w  w  w .  j  a v  a  2s  . co m
    return option;
}

From source file:ch.ethz.topobench.graph.utility.CmdAssistant.java

/**
 * Add a required option to the options with the given name and description.
 *
 * @param options   Options set for the command line
 * @param arg       Argument name (- variant)
 * @param desc      Description/*from w ww  .  j  ava  2  s  . co m*/
 */
public static void addOption(Options options, String arg, String desc) {
    Option opt = new Option(arg, true, desc);
    opt.setRequired(true);
    options.addOption(opt);
}

From source file:com.amit.api.compiler.App.java

private static Options createOptions() {
    Option project = new Option("p", "project", true, "the path to amit project file.");
    project.setRequired(true);

    Option template = new Option("t", "template", true,
            "the path to the template used to generate the result.");
    template.setRequired(true);/* w  w  w .j  a  v  a2 s .  c  o  m*/

    Option dest = new Option("d", "destination", true, "the destination to generate the files.");
    dest.setRequired(true);

    Options options = new Options();
    options.addOption(project);
    options.addOption(template);
    options.addOption(dest);

    return options;
}

From source file:ch.ethz.topobench.graph.utility.CmdAssistant.java

/**
 * Add an option to the options./*from w  w  w. ja v  a2 s. c  o  m*/
 *
 * @param options   Options set for the command line
 * @param argShort  Short argument (-variant)
 * @param argLong   Long argument (-- variant)
 * @param required  Whether it is required
 * @param desc      Description
 */
public static void addOption(Options options, String argShort, String argLong, boolean required, String desc) {
    Option opt = new Option(argShort, argLong, true, desc);
    opt.setRequired(required);
    options.addOption(opt);
}

From source file:info.bitoo.utils.BiToorrentRemaker.java

/**
 * @return// w  ww.j  ava  2  s . c om
 */
private static Options createCommandLineOptions() {
    Option optTorrent = new Option("t", "torrent", true, "torrent file to remake");
    optTorrent.setRequired(true);

    Option optLocations = new Option("l", "locations", true,
            "pipe separated list of alternative download locations.");
    optLocations.setRequired(true);

    Options cliOptions = new Options();
    cliOptions.addOption(optTorrent);
    cliOptions.addOption(optLocations);

    return cliOptions;
}

From source file:de.uni_koblenz.jgralab.utilities.tg2schemagraph.Tg2SchemaGraph.java

private static CommandLine processCommandLineOptions(String[] args) {
    String toolString = "java " + Tg2SchemaGraph.class.getName();
    String versionString = JGraLab.getInfo(false);
    OptionHandler oh = new OptionHandler(toolString, versionString);

    Option output = new Option("o", "output", true, "(required): the output file name");
    output.setRequired(true);
    output.setArgName("file");
    oh.addOption(output);/*from  w ww .j av  a  2s .  c  om*/

    Option schema = new Option("s", "schema", true,
            "(required): the schema of which a schemaGraph should be generated");
    schema.setRequired(true);
    schema.setArgName("file");
    oh.addOption(schema);

    return oh.parse(args);
}

From source file:com.opengamma.integration.tool.marketdata.MarketDataSnapshotImportTool.java

private static Option createFilenameOption() {
    final Option option = new Option(FILE_NAME_OPTION, "filename", true, "The path to the file to import");
    option.setRequired(true);
    return option;
}

From source file:com.damon.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);/*from w w w  .j a v a  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.alibaba.rocketmq.srvutil.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  .co  m

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

    return options;
}

From source file:com.damon.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. java 2  s  . c o  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;
}