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;
}
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;
}
};
}
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;
}
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);
}
Aggregations