use of org.apache.hbase.thirdparty.org.apache.commons.cli.MissingOptionException in project hbase by apache.
the class AbstractHBaseTool method run.
@Override
public int run(String[] args) throws IOException {
cmdLineArgs = args;
Objects.requireNonNull(conf, "Tool configuration is not initialized");
CommandLine cmd;
List<String> argsList = new ArrayList<>(args.length);
for (String arg : args) {
argsList.add(arg);
}
// For backward compatibility of args which can't be parsed as Option. See javadoc for
// processOldArgs(..)
processOldArgs(argsList);
try {
addOptions();
if (isHelpCommand(args)) {
printUsage();
return EXIT_SUCCESS;
}
String[] remainingArgs = new String[argsList.size()];
argsList.toArray(remainingArgs);
cmd = newParser().parse(options, remainingArgs);
} catch (MissingOptionException e) {
LOG.error(e.getMessage());
LOG.error("Use -h or --help for usage instructions.");
return EXIT_FAILURE;
} catch (ParseException e) {
LOG.error("Error when parsing command-line arguments", e);
LOG.error("Use -h or --help for usage instructions.");
return EXIT_FAILURE;
}
processOptions(cmd);
int ret;
try {
ret = doWork();
} catch (Exception e) {
LOG.error("Error running command-line tool", e);
return EXIT_FAILURE;
}
return ret;
}
use of org.apache.hbase.thirdparty.org.apache.commons.cli.MissingOptionException 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;
}
};
}
Aggregations