Example usage for org.apache.commons.cli OptionBuilder hasArgs

List of usage examples for org.apache.commons.cli OptionBuilder hasArgs

Introduction

In this page you can find the example usage for org.apache.commons.cli OptionBuilder hasArgs.

Prototype

public static OptionBuilder hasArgs(int num) 

Source Link

Document

The next Option created can have num argument values.

Usage

From source file:com.google.api.ads.adwords.keywordoptimizer.KeywordOptimizer.java

/**
 * Creates the command line structure / options.
 *
 * @return the command line {@link Options}
 *///  w  w w.  j av a2 s. c  om
private static Options createCommandLineOptions() {
    Options options = new Options();

    OptionBuilder.withLongOpt("keyword-properties");
    OptionBuilder.withDescription("Location of the keyword-optimizer.properties file.");
    OptionBuilder.hasArg(true);
    OptionBuilder.withArgName("file");
    options.addOption(OptionBuilder.create("kp"));

    OptionBuilder.withLongOpt("ads-properties");
    OptionBuilder.withDescription("Location of the ads.properties file.");
    OptionBuilder.hasArg(true);
    OptionBuilder.withArgName("file");
    options.addOption(OptionBuilder.create("ap"));

    OptionBuilder.withLongOpt("help");
    OptionBuilder.withDescription("Shows this help screen.");
    OptionBuilder.withArgName("help");
    options.addOption(OptionBuilder.create("h"));

    OptionBuilder.withLongOpt("seed-keywords");
    OptionBuilder.withDescription("Use the given keywords (separated by spaces) as a seed for the optimization."
            + "\nNote: Only one seed-* option is allowed.");
    OptionBuilder.hasArg(true);
    OptionBuilder.hasArgs(Option.UNLIMITED_VALUES);
    OptionBuilder.withArgName("keywords");
    options.addOption(OptionBuilder.create("sk"));

    OptionBuilder.withLongOpt("seed-keywords-file");
    OptionBuilder.withDescription(
            "Use the keywords from the given file (one keyword per row) as a seed for the optimization."
                    + "\nNote: Only one seed-* option is allowed.");
    OptionBuilder.hasArg(true);
    OptionBuilder.withArgName("file");
    options.addOption(OptionBuilder.create("skf"));

    OptionBuilder.withLongOpt("seed-terms");
    OptionBuilder
            .withDescription("Use the given search terms (separated by spaces) as a seed for the optimization."
                    + "\nNote: Only one seed-* option is allowed.");
    OptionBuilder.hasArg(true);
    OptionBuilder.hasArgs(Option.UNLIMITED_VALUES);
    OptionBuilder.withArgName("terms");
    options.addOption(OptionBuilder.create("st"));

    OptionBuilder.withLongOpt("seed-terms-file");
    OptionBuilder.withDescription("Use the search terms from the given file (one keyword per row) as a seed "
            + "for the optimization.\nNote: Only one seed-* option is allowed.");
    OptionBuilder.hasArg(true);
    OptionBuilder.withArgName("file");
    options.addOption(OptionBuilder.create("stf"));

    OptionBuilder.withLongOpt("seed-urls");
    OptionBuilder.withDescription("Use the given urls (separated by spaces) to extract keywords as a seed for "
            + "the optimization.\nNote: Only one seed-* option is allowed.");
    OptionBuilder.hasArg(true);
    OptionBuilder.hasArgs(Option.UNLIMITED_VALUES);
    OptionBuilder.withArgName("urls");
    options.addOption(OptionBuilder.create("su"));

    OptionBuilder.withLongOpt("seed-urls-file");
    OptionBuilder
            .withDescription("Use the urls from the given file (one url per row) to extract keywords as a seed "
                    + "for the optimization.\nNote: Only one seed-* option is allowed.");
    OptionBuilder.hasArg(true);
    OptionBuilder.withArgName("file");
    options.addOption(OptionBuilder.create("suf"));

    OptionBuilder.withLongOpt("seed-category");
    OptionBuilder.withDescription(
            "Use the given category (ID as defined @ https://goo.gl/xUEr6s) to get keywords as a seed "
                    + "for the optimization.\nNote: Only one seed-* option is allowed.");
    OptionBuilder.hasArg(true);
    OptionBuilder.withArgName("id");
    options.addOption(OptionBuilder.create("sc"));

    OptionBuilder.withLongOpt("match-types");
    OptionBuilder.withDescription("Use the given keyword match types (EXACT, BROAD, PHRASE).");
    OptionBuilder.hasArg(true);
    OptionBuilder.hasArgs(3);
    OptionBuilder.withArgName("types");
    options.addOption(OptionBuilder.create("m"));

    OptionBuilder.withLongOpt("max-cpc");
    OptionBuilder.withDescription("Use the given maximum CPC (in USD, e.g., 5.0 for $5).");
    OptionBuilder.hasArg(true);
    OptionBuilder.withArgName("double");
    options.addOption(OptionBuilder.create("cpc"));

    OptionBuilder.withLongOpt("locations");
    OptionBuilder.withDescription("Use the given locations IDs (ID as defined @ https://goo.gl/TA5E81) for "
            + "geo-targeted results.");
    OptionBuilder.hasArg(true);
    OptionBuilder.hasArgs(Option.UNLIMITED_VALUES);
    OptionBuilder.withArgName("ids");
    options.addOption(OptionBuilder.create("loc"));

    OptionBuilder.withLongOpt("languages");
    OptionBuilder.withDescription("Use the given locations IDs (ID as defined @ https://goo.gl/WWzifs) for "
            + "language-targeted results.");
    OptionBuilder.hasArg(true);
    OptionBuilder.hasArgs(Option.UNLIMITED_VALUES);
    OptionBuilder.withArgName("ids");
    options.addOption(OptionBuilder.create("lang"));

    OptionBuilder.withLongOpt("output");
    OptionBuilder.withDescription("Mode for outputting results (CONSOLE / CSV)\nNote: If set to CSV, then "
            + "option -of also has to be specified.");
    OptionBuilder.hasArg(true);
    OptionBuilder.hasArgs(2);
    OptionBuilder.withArgName("mode");
    options.addOption(OptionBuilder.create("o"));

    OptionBuilder.withLongOpt("output-file");
    OptionBuilder.withDescription("File to for writing output data (only needed if option -o is specified).");
    OptionBuilder.hasArg(true);
    OptionBuilder.withArgName("file");
    options.addOption(OptionBuilder.create("of"));

    return options;
}

From source file:edu.usc.scrc.PriorityPruner.CommandLineOptions.java

/**
 * Creates an Option-object with both a full and a shorthand version of its
 * name.//  ww w. ja  va  2  s  . c  om
 * 
 * @param numArgs
 *            number of arguments required for every argument entry
 * @param typeOfArg
 *            type of argument expected
 * @param longOpt
 *            full name of this option
 * @param desc
 *            description of this option
 * @param isReq
 *            specifies if this option is required or not
 * @param shortOpt
 *            shorthand name for this option
 * @return a static Option-object
 */
private static Option createOptionTwoNames(int numArgs, String typeOfArg, String longOpt, String desc,
        boolean isReq, String shortOpt) {

    OptionBuilder.hasArgs(numArgs);
    OptionBuilder.withArgName(typeOfArg);
    OptionBuilder.withLongOpt(longOpt);
    OptionBuilder.withDescription(desc);
    OptionBuilder.isRequired(isReq);
    return OptionBuilder.create(shortOpt);
}

From source file:com.hortonworks.registries.storage.tool.TablesInitializer.java

private static Option option(int argCount, String shortName, String longName, String argName,
        String description) {/*  w  w w  . j  a v a  2 s.c o  m*/
    return OptionBuilder.hasArgs(argCount).withArgName(argName).withLongOpt(longName)
            .withDescription(description).create(shortName);
}

From source file:edu.usc.scrc.PriorityPruner.CommandLineOptions.java

/**
 * Creates an Option-object with specified parameters, without a shorthand
 * version of its name./*from   w w w.  j  a v a  2s.  c  o m*/
 * 
 * @param numArgs
 *            number of arguments required for an argument entry
 * @param typeOfArg
 *            type of argument expected
 * @param desc
 *            description of this option
 * @param isReq
 *            specifies if this option is required or not
 * @param shortOpt
 *            short name for this option
 * @return a static Option-object
 */
private static Option createOptionOneName(int numArgs, String typeOfArg, String desc, boolean isReq,
        String longOpt) {

    OptionBuilder.hasArgs(numArgs);
    OptionBuilder.withArgName(typeOfArg);
    OptionBuilder.withDescription(desc);
    OptionBuilder.isRequired(isReq);
    return OptionBuilder.create(longOpt);
}

From source file:com.google.api.ads.adwords.jaxws.extensions.AwReporting.java

/**
 * Creates the command line options./*w w w . ja va  2  s. co m*/
 *
 * @return the {@link Options}.
 */
private static Options createCommandLineOptions() {

    Options options = new Options();
    Option help = new Option("help", "print this message");
    options.addOption(help);

    OptionBuilder.withArgName("file");
    OptionBuilder.hasArg(true);
    OptionBuilder.withDescription("aw-report-sample.properties file.");
    OptionBuilder.isRequired(false);
    options.addOption(OptionBuilder.create("file"));

    OptionBuilder.withArgName("YYYYMMDD");
    OptionBuilder.hasArg(true);
    OptionBuilder.withDescription("Start date for CUSTOM_DATE Reports (YYYYMMDD)");
    OptionBuilder.isRequired(false);
    options.addOption(OptionBuilder.create("startDate"));

    OptionBuilder.withArgName("YYYMMDD");
    OptionBuilder.hasArg(true);
    OptionBuilder.withDescription("End date for CUSTOM_DATE Reports (YYYYMMDD)");
    OptionBuilder.isRequired(false);
    options.addOption(OptionBuilder.create("endDate"));

    OptionBuilder.withArgName("DateRangeType");
    OptionBuilder.hasArg(true);
    OptionBuilder.withDescription("ReportDefinitionDateRangeType");
    OptionBuilder.isRequired(false);
    options.addOption(OptionBuilder.create("dateRange"));

    OptionBuilder.withArgName("htmlTemplateFile> <outputDirectory");
    OptionBuilder.withValueSeparator(' ');
    OptionBuilder.hasArgs(2);
    OptionBuilder.withDescription("Generate Monthly Account Reports for all Accounts in PDF\n"
            + "NOTE: For PDF use aw-report-sample-for-pdf.properties instead, the fields need to be different.");
    options.addOption(OptionBuilder.create("generatePdf"));

    OptionBuilder.withArgName("accountIdsFile");
    OptionBuilder.hasArg(true);
    OptionBuilder.withDescription("Consider ONLY the account IDs specified on the file to run the report");
    OptionBuilder.isRequired(false);
    options.addOption(OptionBuilder.create("accountIdsFile"));

    OptionBuilder.withArgName("verbose");
    OptionBuilder.hasArg(false);
    OptionBuilder.withDescription("The application will print all the tracing on the console");
    OptionBuilder.isRequired(false);
    options.addOption(OptionBuilder.create("verbose"));

    OptionBuilder.withArgName("debug");
    OptionBuilder.hasArg(false);
    OptionBuilder.withDescription(
            "Will display all the debug information. " + "If the option 'verbose' is activated, "
                    + "all the information will be displayed on the console as well");
    OptionBuilder.isRequired(false);
    options.addOption(OptionBuilder.create("debug"));

    return options;
}

From source file:com.sindicetech.siren.demo.loader.Loader.java

private static Options buildOptions() {
    Options options = new Options();
    // input file name and help are exclusive
    OptionGroup fileHelpGroup = new OptionGroup();
    fileHelpGroup.setRequired(true);/*  www. j ava 2  s  . c  o m*/
    fileHelpGroup
            .addOption(OptionBuilder.hasArgs(1).hasOptionalArgs(20).withArgName("file or/and folder name[s]")
                    .withDescription("JSON file[s] or/and director(y|ies) with JSON files (max 20)")
                    .withLongOpt(INPUT_FILE_OPT_LONG).isRequired().create(INPUT_FILE_OPT));

    fileHelpGroup.addOption(OptionBuilder.withDescription("prints help and exits").create(HELP_OPT));
    options.addOptionGroup(fileHelpGroup);
    options.addOption(OptionBuilder.hasArgs(1).withArgName("Solr URL")
            .withDescription("Solr URL (default=" + DEFAULT_SOLR_URL + ")").withLongOpt(URL_OPT_LONG)
            .isRequired(false).create(URL_OPT));

    //    options.addOption(OptionBuilder
    //        .hasArgs(1)
    //        .withArgName("batch size")
    //        .withDescription(
    //            "number of documents sent to Solr in one request, max " + MAX_BATCH_SIZE + " (default="
    //                + DEFAULT_BATCH_SIZE + ")").withLongOpt(BATCH_OPT_LONG).isRequired(false)
    //        .create(BATCH_OPT));

    options.addOption(OptionBuilder
            .withDescription("load all files in directories, not only files with JSON file extension")
            .withLongOpt(NO_EXT_CHECK_OPT_LONG).isRequired(false).create(NO_EXT_CHECK_OPT));
    options.addOption(
            OptionBuilder.withDescription("JSON file extension (default=" + DEFAULT_JSON_EXTENSION + ")")
                    .withLongOpt(EXT_OPT_LONG).isRequired(false).create(EXT_OPT));
    options.addOption(OptionBuilder.withDescription("commit after each file, (default=false)")
            .withLongOpt(COMMIT_EACH_LONG).isRequired(false).create(COMMIT_EACH_OPT));

    return options;
}

From source file:org.apache.ambari.client.ClusterCreate.java

public void addOptions() {

    Option wait = new Option("wait", "Optionally wait for cluster to reach desired state");
    Option dry_run = new Option("dry_run", "Dry run");
    Option help = new Option("help", "Help");

    OptionBuilder.withArgName("cluster_name");
    OptionBuilder.isRequired();/*  w w  w.  j  a  v a2 s . c  o m*/
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("Name of the cluster to be created");
    Option name = OptionBuilder.create("name");

    OptionBuilder.withArgName("stack_name");
    OptionBuilder.isRequired();
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("Name of the cluster stack");
    Option stack = OptionBuilder.create("stack");

    OptionBuilder.withArgName("\"node_exp1; node_exp2; ...\"");
    OptionBuilder.isRequired();
    OptionBuilder.hasArg();
    OptionBuilder.withDescription(
            "List of node range expressions separated by semicolon (;) and contained in double quotes (\"\")");
    Option nodes = OptionBuilder.create("nodes");

    OptionBuilder.withArgName("stack_revision");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("Stack revision, if not specified latest revision is used");
    Option revision = OptionBuilder.create("revision");

    OptionBuilder.withArgName("description");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("Description to be associated with cluster");
    Option desc = OptionBuilder.create("desc");

    OptionBuilder.withArgName("goalstate");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("Desired goal state of the cluster");
    Option goalstate = OptionBuilder.create("goalstate");

    OptionBuilder.withArgName("\"component-1; component-2; ...\"");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription(
            "List of components to be active in the cluster. Components are seperated by semicolon \";\"");
    Option services = OptionBuilder.create("services");

    OptionBuilder.withArgName("rolename=\"node_exp1; node_exp2; ... \"");
    OptionBuilder.hasArgs(2);
    OptionBuilder.withValueSeparator();
    OptionBuilder.withDescription(
            "Provide node range expressions for a given rolename separated by semicolon (;) and contained in double quotes (\"\")");
    Option role = OptionBuilder.create("role");

    this.options = new Options();
    options.addOption(wait);
    options.addOption(dry_run);
    options.addOption(name);
    options.addOption(stack);
    options.addOption(revision);
    options.addOption(desc);
    options.addOption(role);
    options.addOption(goalstate);
    options.addOption(nodes);
    options.addOption(services);
    options.addOption(help);
}

From source file:org.apache.ambari.client.ClusterUpdate.java

public void addOptions() {

    Option wait = new Option("wait", "Optionally wait for cluster to reach desired state");
    Option dry_run = new Option("dry_run", "Dry run");
    Option help = new Option("help", "Help");

    OptionBuilder.withArgName("cluster_name");
    OptionBuilder.isRequired();//ww w .  j  av  a  2  s  .  c  o m
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("Name of the cluster to be updated");
    Option name = OptionBuilder.create("name");

    OptionBuilder.withArgName("stack_name");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("Name of the cluster stack");
    Option stack = OptionBuilder.create("stack");

    OptionBuilder.withArgName("\"node_exp1; node_exp2; ...\"");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription(
            "List of node range expressions separated by semicolon (;) and contained in double quotes (\"\")");
    Option nodes = OptionBuilder.create("nodes");

    OptionBuilder.withArgName("stack_revision");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("Stack revision");
    Option revision = OptionBuilder.create("revision");

    OptionBuilder.withArgName("description");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("Description associated with cluster");
    Option desc = OptionBuilder.create("desc");

    OptionBuilder.withArgName("goalstate");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("Desired goal state of the cluster");
    Option goalstate = OptionBuilder.create("goalstate");

    OptionBuilder.withArgName("\"component-1; component-2; ...\"");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription(
            "List of components to be active in the cluster. Components are seperated by semicolon \";\"");
    Option services = OptionBuilder.create("services");

    OptionBuilder.withArgName("rolename=\"node_exp1; node_exp2; ... \"");
    OptionBuilder.hasArgs(2);
    OptionBuilder.withValueSeparator();
    OptionBuilder.withDescription(
            "Node range expressions for a given rolename separated by semicolon (;) and contained in double quotes (\"\")");
    Option role = OptionBuilder.create("role");

    this.options = new Options();
    options.addOption(wait);
    options.addOption(dry_run);
    options.addOption(name);
    options.addOption(stack);
    options.addOption(revision);
    options.addOption(desc);
    options.addOption(role);
    options.addOption(goalstate);
    options.addOption(nodes);
    options.addOption(services);
    options.addOption(help);
}

From source file:org.apache.hadoop.hive.llap.cli.LlapStatusOptionsProcessor.java

public LlapStatusOptionsProcessor() {

    for (OptionConstants optionConstant : OptionConstants.values()) {

        OptionBuilder optionBuilder = OptionBuilder.hasArgs(optionConstant.getNumArgs())
                .withArgName(optionConstant.getArgName()).withLongOpt(optionConstant.getLongOpt())
                .withDescription(optionConstant.getDescription());
        if (optionConstant.getShortOpt() == null) {
            options.addOption(optionBuilder.create());
        } else {//  w  ww. j av  a  2s. com
            options.addOption(optionBuilder.create(optionConstant.getShortOpt()));
        }
    }
}

From source file:org.apache.hcatalog.cli.HCatCli.java

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

    try {//  www  .  j  a v a  2 s.c o m
        LogUtils.initHiveLog4j();
    } catch (LogInitializationException e) {

    }

    CliSessionState ss = new CliSessionState(new HiveConf(SessionState.class));
    ss.in = System.in;
    try {
        ss.out = new PrintStream(System.out, true, "UTF-8");
        ss.err = new PrintStream(System.err, true, "UTF-8");
    } catch (UnsupportedEncodingException e) {
        System.exit(1);
    }

    HiveConf conf = ss.getConf();

    HiveConf.setVar(conf, ConfVars.SEMANTIC_ANALYZER_HOOK, HCatSemanticAnalyzer.class.getName());

    SessionState.start(ss);

    Options options = new Options();

    // -e 'quoted-query-string'
    options.addOption(OptionBuilder.hasArg().withArgName("exec")
            .withDescription("hcat command given from command line").create('e'));

    // -f <query-file>
    options.addOption(
            OptionBuilder.hasArg().withArgName("file").withDescription("hcat commands in file").create('f'));

    // -g
    options.addOption(OptionBuilder.hasArg().withArgName("group")
            .withDescription("group for the db/table specified in CREATE statement").create('g'));

    // -p
    options.addOption(OptionBuilder.hasArg().withArgName("perms")
            .withDescription("permissions for the db/table specified in CREATE statement").create('p'));

    // -D
    options.addOption(OptionBuilder.hasArgs(2).withArgName("property=value").withValueSeparator()
            .withDescription("use hadoop value for given property").create('D'));

    // [-h|--help]
    options.addOption(new Option("h", "help", false, "Print help information"));

    Parser parser = new GnuParser();
    CommandLine cmdLine = null;

    try {
        cmdLine = parser.parse(options, args);

    } catch (ParseException e) {
        printUsage(options, ss.err);
        System.exit(1);
    }
    // -e
    String execString = (String) cmdLine.getOptionValue('e');
    // -f
    String fileName = (String) cmdLine.getOptionValue('f');
    // -h
    if (cmdLine.hasOption('h')) {
        printUsage(options, ss.out);
        System.exit(0);
    }

    if (execString != null && fileName != null) {
        ss.err.println("The '-e' and '-f' options cannot be specified simultaneously");
        printUsage(options, ss.err);
        System.exit(1);
    }

    // -p
    String perms = (String) cmdLine.getOptionValue('p');
    if (perms != null) {
        validatePermissions(ss, conf, perms);
    }

    // -g
    String grp = (String) cmdLine.getOptionValue('g');
    if (grp != null) {
        conf.set(HCatConstants.HCAT_GROUP, grp);
    }

    // -D
    setConfProperties(conf, cmdLine.getOptionProperties("D"));

    if (execString != null) {
        System.exit(processLine(execString));
    }

    try {
        if (fileName != null) {
            System.exit(processFile(fileName));
        }
    } catch (FileNotFoundException e) {
        ss.err.println("Input file not found. (" + e.getMessage() + ")");
        System.exit(1);
    } catch (IOException e) {
        ss.err.println("Could not open input file for reading. (" + e.getMessage() + ")");
        System.exit(1);
    }

    // -h
    printUsage(options, ss.err);
    System.exit(1);
}