Search in sources :

Example 11 with Option

use of org.apache.commons.cli.Option in project hadoop by apache.

the class TimelineSchemaCreator method parseArgs.

/**
   * Parse command-line arguments.
   *
   * @param args
   *          command line arguments passed to program.
   * @return parsed command line.
   * @throws ParseException
   */
private static CommandLine parseArgs(String[] args) throws ParseException {
    Options options = new Options();
    // Input
    Option o = new Option(ENTITY_TABLE_NAME_SHORT, "entityTableName", true, "entity table name");
    o.setArgName("entityTableName");
    o.setRequired(false);
    options.addOption(o);
    o = new Option(TTL_OPTION_SHORT, "metricsTTL", true, "TTL for metrics column family");
    o.setArgName("metricsTTL");
    o.setRequired(false);
    options.addOption(o);
    o = new Option(APP_TO_FLOW_TABLE_NAME_SHORT, "appToflowTableName", true, "app to flow table name");
    o.setArgName("appToflowTableName");
    o.setRequired(false);
    options.addOption(o);
    o = new Option(APP_TABLE_NAME_SHORT, "applicationTableName", true, "application table name");
    o.setArgName("applicationTableName");
    o.setRequired(false);
    options.addOption(o);
    // Options without an argument
    // No need to set arg name since we do not need an argument here
    o = new Option(SKIP_EXISTING_TABLE_OPTION_SHORT, "skipExistingTable", false, "skip existing Hbase tables and continue to create new tables");
    o.setRequired(false);
    options.addOption(o);
    CommandLineParser parser = new PosixParser();
    CommandLine commandLine = null;
    try {
        commandLine = parser.parse(options, args);
    } catch (Exception e) {
        LOG.error("ERROR: " + e.getMessage() + "\n");
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(NAME + " ", options, true);
        System.exit(-1);
    }
    return commandLine;
}
Also used : HelpFormatter(org.apache.commons.cli.HelpFormatter) Options(org.apache.commons.cli.Options) CommandLine(org.apache.commons.cli.CommandLine) PosixParser(org.apache.commons.cli.PosixParser) Option(org.apache.commons.cli.Option) CommandLineParser(org.apache.commons.cli.CommandLineParser) IOException(java.io.IOException) ParseException(org.apache.commons.cli.ParseException)

Example 12 with Option

use of org.apache.commons.cli.Option in project hive by apache.

the class HiveMetaTool method init.

@SuppressWarnings("static-access")
private void init() {
    System.out.println("Initializing HiveMetaTool..");
    Option help = new Option("help", "print this message");
    Option listFSRoot = new Option("listFSRoot", "print the current FS root locations");
    Option executeJDOQL = OptionBuilder.withArgName("query-string").hasArgs().withDescription("execute the given JDOQL query").create("executeJDOQL");
    /* Ideally we want to specify the different arguments to updateLocation as separate argNames.
     * However if we did that, HelpFormatter swallows all but the last argument. Note that this is
     * a know issue with the HelpFormatter class that has not been fixed. We specify all arguments
     * with a single argName to workaround this HelpFormatter bug.
     */
    Option updateFSRootLoc = OptionBuilder.withArgName("new-loc> " + "<old-loc").hasArgs(2).withDescription("Update FS root location in the metastore to new location.Both new-loc and " + "old-loc should be valid URIs with valid host names and schemes." + "When run with the dryRun option changes are displayed but are not " + "persisted. When run with the serdepropKey/tablePropKey option " + "updateLocation looks for the serde-prop-key/table-prop-key that is " + "specified and updates its value if found.").create("updateLocation");
    Option dryRun = new Option("dryRun", "Perform a dry run of updateLocation changes.When " + "run with the dryRun option updateLocation changes are displayed but not persisted. " + "dryRun is valid only with the updateLocation option.");
    Option serdePropKey = OptionBuilder.withArgName("serde-prop-key").hasArgs().withValueSeparator().withDescription("Specify the key for serde property to be updated. serdePropKey option " + "is valid only with updateLocation option.").create("serdePropKey");
    Option tablePropKey = OptionBuilder.withArgName("table-prop-key").hasArg().withValueSeparator().withDescription("Specify the key for table property to be updated. tablePropKey option " + "is valid only with updateLocation option.").create("tablePropKey");
    cmdLineOptions.addOption(help);
    cmdLineOptions.addOption(listFSRoot);
    cmdLineOptions.addOption(executeJDOQL);
    cmdLineOptions.addOption(updateFSRootLoc);
    cmdLineOptions.addOption(dryRun);
    cmdLineOptions.addOption(serdePropKey);
    cmdLineOptions.addOption(tablePropKey);
}
Also used : Option(org.apache.commons.cli.Option)

Example 13 with Option

use of org.apache.commons.cli.Option in project hbase by apache.

the class TestJoinedScanners method main.

/**
   * Command line interface:
   * @param args
   * @throws IOException if there is a bug while reading from disk
   */
public static void main(final String[] args) throws Exception {
    Option encodingOption = new Option("e", "blockEncoding", true, "Data block encoding; Default: FAST_DIFF");
    encodingOption.setRequired(false);
    options.addOption(encodingOption);
    Option ratioOption = new Option("r", "selectionRatio", true, "Ratio of selected rows using essential column family");
    ratioOption.setRequired(false);
    options.addOption(ratioOption);
    Option widthOption = new Option("w", "valueWidth", true, "Width of value for non-essential column family");
    widthOption.setRequired(false);
    options.addOption(widthOption);
    CommandLineParser parser = new GnuParser();
    CommandLine cmd = parser.parse(options, args);
    if (args.length < 1) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("TestJoinedScanners", options, true);
    }
    if (cmd.hasOption("e")) {
        blockEncoding = DataBlockEncoding.valueOf(cmd.getOptionValue("e"));
    }
    if (cmd.hasOption("r")) {
        selectionRatio = Integer.parseInt(cmd.getOptionValue("r"));
    }
    if (cmd.hasOption("w")) {
        valueWidth = Integer.parseInt(cmd.getOptionValue("w"));
    }
    // run the test
    TestJoinedScanners test = new TestJoinedScanners();
    test.testJoinedScanners();
}
Also used : HelpFormatter(org.apache.commons.cli.HelpFormatter) CommandLine(org.apache.commons.cli.CommandLine) GnuParser(org.apache.commons.cli.GnuParser) Option(org.apache.commons.cli.Option) CommandLineParser(org.apache.commons.cli.CommandLineParser)

Example 14 with Option

use of org.apache.commons.cli.Option in project moco by dreamhead.

the class StartArgsParser method cert.

protected Option cert() {
    Option option = new Option(null, "cert", true, "Cert password");
    option.setType(String.class);
    option.setRequired(false);
    return option;
}
Also used : Option(org.apache.commons.cli.Option)

Example 15 with Option

use of org.apache.commons.cli.Option in project moco by dreamhead.

the class ShutdownArgs method createShutdownOptions.

private static Options createShutdownOptions() {
    Options options = new Options();
    Option option = shutdownPortOption();
    option.setRequired(true);
    options.addOption(option);
    return options;
}
Also used : Options(org.apache.commons.cli.Options) Option(org.apache.commons.cli.Option)

Aggregations

Option (org.apache.commons.cli.Option)152 Options (org.apache.commons.cli.Options)105 CommandLine (org.apache.commons.cli.CommandLine)53 CommandLineParser (org.apache.commons.cli.CommandLineParser)52 ParseException (org.apache.commons.cli.ParseException)41 GnuParser (org.apache.commons.cli.GnuParser)39 HelpFormatter (org.apache.commons.cli.HelpFormatter)30 File (java.io.File)13 OptionGroup (org.apache.commons.cli.OptionGroup)13 FileInputStream (java.io.FileInputStream)10 IOException (java.io.IOException)10 HashMap (java.util.HashMap)9 DefaultParser (org.apache.commons.cli.DefaultParser)9 Properties (java.util.Properties)8 BasicParser (org.apache.commons.cli.BasicParser)6 ConsoleAppender (org.apache.log4j.ConsoleAppender)6 PatternLayout (org.apache.log4j.PatternLayout)6 ArrayList (java.util.ArrayList)5 PosixParser (org.apache.commons.cli.PosixParser)5 List (java.util.List)3