Search in sources :

Example 1 with AlreadySelectedException

use of org.apache.hbase.thirdparty.org.apache.commons.cli.AlreadySelectedException 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)

Aggregations

Properties (java.util.Properties)1 AlreadySelectedException (org.apache.hbase.thirdparty.org.apache.commons.cli.AlreadySelectedException)1 CommandLine (org.apache.hbase.thirdparty.org.apache.commons.cli.CommandLine)1 DefaultParser (org.apache.hbase.thirdparty.org.apache.commons.cli.DefaultParser)1 MissingOptionException (org.apache.hbase.thirdparty.org.apache.commons.cli.MissingOptionException)1 Options (org.apache.hbase.thirdparty.org.apache.commons.cli.Options)1