Search in sources :

Example 6 with DefaultParser

use of org.apache.hbase.thirdparty.org.apache.commons.cli.DefaultParser in project hbase by apache.

the class AbstractHBaseTool method isHelpCommand.

private boolean isHelpCommand(String[] args) throws ParseException {
    Options helpOption = new Options().addOption(HELP_OPTION);
    // this parses the command line but doesn't throw an exception on unknown options
    CommandLine cl = new DefaultParser().parse(helpOption, args, true);
    return cl.getOptions().length != 0;
}
Also used : Options(org.apache.hbase.thirdparty.org.apache.commons.cli.Options) CommandLine(org.apache.hbase.thirdparty.org.apache.commons.cli.CommandLine) DefaultParser(org.apache.hbase.thirdparty.org.apache.commons.cli.DefaultParser)

Example 7 with DefaultParser

use of org.apache.hbase.thirdparty.org.apache.commons.cli.DefaultParser in project hbase by apache.

the class LoadTestTool method newParser.

@Override
protected CommandLineParser newParser() {
    // Validate in parse() to get helpful error messages instead of exploding in processOptions()
    return new DefaultParser() {

        @Override
        public CommandLine parse(Options opts, String[] args, Properties props, boolean stop) throws ParseException {
            CommandLine cl = super.parse(opts, args, props, stop);
            boolean isReadWriteUpdate = cmd.hasOption(OPT_READ) || cmd.hasOption(OPT_WRITE) || cmd.hasOption(OPT_UPDATE);
            boolean isInitOnly = cmd.hasOption(OPT_INIT_ONLY);
            if (!isInitOnly && !isReadWriteUpdate) {
                throw new MissingOptionException("Must specify either -" + OPT_INIT_ONLY + " or at least one of -" + OPT_READ + ", -" + OPT_WRITE + ", -" + OPT_UPDATE);
            }
            if (isInitOnly && isReadWriteUpdate) {
                throw new AlreadySelectedException(OPT_INIT_ONLY + " cannot be specified with any of -" + OPT_READ + ", -" + OPT_WRITE + ", -" + OPT_UPDATE);
            }
            if (isReadWriteUpdate && !cmd.hasOption(OPT_NUM_KEYS)) {
                throw new MissingOptionException(OPT_NUM_KEYS + " must be specified in read/write mode.");
            }
            return cl;
        }
    };
}
Also used : Options(org.apache.hbase.thirdparty.org.apache.commons.cli.Options) CommandLine(org.apache.hbase.thirdparty.org.apache.commons.cli.CommandLine) AlreadySelectedException(org.apache.hbase.thirdparty.org.apache.commons.cli.AlreadySelectedException) Properties(java.util.Properties) MissingOptionException(org.apache.hbase.thirdparty.org.apache.commons.cli.MissingOptionException) DefaultParser(org.apache.hbase.thirdparty.org.apache.commons.cli.DefaultParser)

Example 8 with DefaultParser

use of org.apache.hbase.thirdparty.org.apache.commons.cli.DefaultParser in project hbase by apache.

the class RegionReplicationLagEvaluation method run.

@Override
public int run(String[] args) throws Exception {
    TableName tableName;
    int rlen;
    int vlen;
    int rows;
    try {
        CommandLine cli = new DefaultParser().parse(OPTIONS, args);
        tableName = TableName.valueOf(cli.getOptionValue("t", TABLE_NAME));
        rlen = Integer.parseInt(cli.getOptionValue("rlen", String.valueOf(ROW_LENGTH)));
        vlen = Integer.parseInt(cli.getOptionValue("vlen", String.valueOf(VALUE_LENGTH)));
        rows = Integer.parseInt(cli.getOptionValue("r"));
    } catch (Exception e) {
        LOG.warn("Error parsing command line options", e);
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(getClass().getName(), OPTIONS);
        return -1;
    }
    exec(tableName, rlen, vlen, rows);
    return 0;
}
Also used : HelpFormatter(org.apache.hbase.thirdparty.org.apache.commons.cli.HelpFormatter) CommandLine(org.apache.hbase.thirdparty.org.apache.commons.cli.CommandLine) IOException(java.io.IOException) DefaultParser(org.apache.hbase.thirdparty.org.apache.commons.cli.DefaultParser)

Example 9 with DefaultParser

use of org.apache.hbase.thirdparty.org.apache.commons.cli.DefaultParser in project hbase by apache.

the class ThriftServer method processOptions.

/**
 * Parse the command line options to set parameters the conf.
 */
protected void processOptions(final String[] args) throws Exception {
    if (args == null || args.length == 0) {
        return;
    }
    Options options = new Options();
    addOptions(options);
    CommandLineParser parser = new DefaultParser();
    CommandLine cmd = parser.parse(options, args);
    if (cmd.hasOption("help")) {
        printUsageAndExit(options, 1);
    }
    parseCommandLine(cmd, options);
}
Also used : Options(org.apache.hbase.thirdparty.org.apache.commons.cli.Options) CommandLine(org.apache.hbase.thirdparty.org.apache.commons.cli.CommandLine) CommandLineParser(org.apache.hbase.thirdparty.org.apache.commons.cli.CommandLineParser) DefaultParser(org.apache.hbase.thirdparty.org.apache.commons.cli.DefaultParser)

Aggregations

CommandLine (org.apache.hbase.thirdparty.org.apache.commons.cli.CommandLine)9 DefaultParser (org.apache.hbase.thirdparty.org.apache.commons.cli.DefaultParser)9 Options (org.apache.hbase.thirdparty.org.apache.commons.cli.Options)8 CommandLineParser (org.apache.hbase.thirdparty.org.apache.commons.cli.CommandLineParser)4 ParseException (org.apache.hbase.thirdparty.org.apache.commons.cli.ParseException)4 Configuration (org.apache.hadoop.conf.Configuration)3 HBaseConfiguration (org.apache.hadoop.hbase.HBaseConfiguration)3 HelpFormatter (org.apache.hbase.thirdparty.org.apache.commons.cli.HelpFormatter)3 ArrayList (java.util.ArrayList)2 IOException (java.io.IOException)1 List (java.util.List)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 Properties (java.util.Properties)1 Collectors (java.util.stream.Collectors)1 Configured (org.apache.hadoop.conf.Configured)1 Path (org.apache.hadoop.fs.Path)1 HBaseInterfaceAudience (org.apache.hadoop.hbase.HBaseInterfaceAudience)1 Field (org.apache.hadoop.hbase.hbtop.field.Field)1 FieldInfo (org.apache.hadoop.hbase.hbtop.field.FieldInfo)1