static TestOptions parseOpts(Queue<String> args) {
    final TestOptions opts = new TestOptions();

    final Map<String, Consumer<Boolean>> flagHandlers = new HashMap<>();
    flagHandlers.put("nomapred", v -> opts.nomapred = v);
    flagHandlers.put("flushCommits", v -> opts.flushCommits = v);
    flagHandlers.put("writeToWAL", v -> opts.writeToWAL = v);
    flagHandlers.put("inmemory", v -> opts.inMemoryCF = v);
    flagHandlers.put("autoFlush", v -> opts.autoFlush = v);
    flagHandlers.put("oneCon", v -> opts.oneCon = v);
    flagHandlers.put("latency", v -> opts.reportLatency = v);
    flagHandlers.put("usetags", v -> opts.useTags = v);
    flagHandlers.put("filterAll", v -> opts.filterAll = v);
    flagHandlers.put("valueRandom", v -> opts.valueRandom = v);
    flagHandlers.put("valueZipf", v -> opts.valueZipf = v);
    flagHandlers.put("addColumns", v -> opts.addColumns = v);
    flagHandlers.put("asyncPrefetch", v -> opts.asyncPrefetch = v);
    flagHandlers.put("cacheBlocks", v -> opts.cacheBlocks = v);

    final Map<String, Consumer<String>> handlers = new HashMap<>();
    handlers.put("rows", v -> opts.perClientRunRows = Long.parseLong(v));
    handlers.put("cycles", v -> opts.cycles = Integer.parseInt(v));
    handlers.put("sampleRate", v -> opts.sampleRate = Float.parseFloat(v));
    handlers.put("table", v -> opts.tableName = v);
    handlers.put("startRow", v -> opts.startRow = Long.parseLong(v));
    handlers.put("compress", v -> opts.compression = Compression.Algorithm.valueOf(v));
    handlers.put("encryption", v -> opts.encryption = v);
    handlers.put("traceRate", v -> opts.traceRate = Double.parseDouble(v));
    handlers.put("blockEncoding", v -> opts.blockEncoding = DataBlockEncoding.valueOf(v));
    handlers.put("presplit", v -> opts.presplitRegions = Integer.parseInt(v));
    handlers.put("connCount", v -> opts.connCount = Integer.parseInt(v));
    handlers.put("latencyThreshold", v -> opts.latencyThreshold = Integer.parseInt(v));
    handlers.put("multiGet", v -> opts.multiGet = Integer.parseInt(v));
    handlers.put("multiPut", v -> opts.multiPut = Integer.parseInt(v));
    handlers.put("numoftags", v -> opts.noOfTags = Integer.parseInt(v));
    handlers.put("replicas", v -> opts.replicas = Integer.parseInt(v));
    handlers.put("size", v -> {
      opts.size = Float.parseFloat(v);
      if (opts.size <= 1.0f) {
        throw new IllegalStateException("Size must be > 1; i.e. 1GB");
      }
    });
    handlers.put("splitPolicy", v -> opts.splitPolicy = v);
    handlers.put("randomSleep", v -> opts.randomSleep = Integer.parseInt(v));
    handlers.put("measureAfter", v -> opts.measureAfter = Integer.parseInt(v));
    handlers.put("bloomFilter", v -> opts.bloomType = BloomType.valueOf(v));
    handlers.put("blockSize", v -> opts.blockSize = Integer.parseInt(v));
    handlers.put("valueSize", v -> opts.valueSize = Integer.parseInt(v));
    handlers.put("period", v -> opts.period = Integer.parseInt(v));
    handlers.put("inmemoryCompaction",
      v -> opts.inMemoryCompaction = MemoryCompactionPolicy.valueOf(v));
    handlers.put("columns", v -> opts.columns = Integer.parseInt(v));
    handlers.put("families", v -> opts.families = Integer.parseInt(v));
    handlers.put("caching", v -> opts.caching = Integer.parseInt(v));
    handlers.put("scanReadType", v -> opts.scanReadType = Scan.ReadType.valueOf(v.toUpperCase()));
    handlers.put("bufferSize", v -> opts.bufferSize = Long.parseLong(v));
    handlers.put("commandPropertiesFile", fileName -> {
      try {
        final Properties properties = new Properties();
        final InputStream resourceStream =
          PerformanceEvaluation.class.getClassLoader().getResourceAsStream(fileName);
        if (resourceStream == null) {
          throw new IllegalArgumentException("Resource file not found: " + fileName);
        }
        properties.load(resourceStream);
        opts.commandProperties = properties;
      } catch (IOException e) {
        throw new IllegalStateException("Failed to load command properties from file: " + fileName,
          e);
      }
    });

    String cmd = null;
    final Splitter splitter = Splitter.on("=").limit(2).trimResults();
    while ((cmd = args.poll()) != null) {
      if (cmd.equals("-h") || cmd.startsWith("--h")) {
        // place item back onto queue so that caller knows parsing was incomplete
        args.add(cmd);
        break;
      }

      if (cmd.startsWith("--")) {
        final List<String> parts = splitter.splitToList(cmd.substring(2));
        final String key = parts.get(0);

        try {
          // Boolean options can be specified as --flag or --flag=true/false
          final Consumer<Boolean> flagHandler = flagHandlers.get(key);
          if (flagHandler != null) {
            flagHandler.accept(parts.size() > 1 ? parseBoolean(parts.get(1)) : true);
            continue;
          }

          // Options that require a value followed by an equals sign
          final Consumer<String> handler = handlers.get(key);
          if (handler != null) {
            if (parts.size() < 2) {
              throw new IllegalArgumentException("--" + key + " requires a value");
            }
            handler.accept(parts.get(1));
            continue;
          }
        } catch (RuntimeException e) {
          throw new IllegalArgumentException("Invalid option: " + cmd, e);
        }
      }

      if (isCommandClass(cmd)) {
        opts.cmdName = cmd;
        try {
          opts.numClientThreads = Integer.parseInt(args.remove());
        } catch (NoSuchElementException | NumberFormatException e) {
          throw new IllegalArgumentException("Command " + cmd + " does not have threads number", e);
        }
        calculateRowsAndSize(opts);
        break;
      }

      printUsageAndExit("ERROR: Unrecognized option/command: " + cmd, -1);
    }

    validateParsedOpts(opts);
    return opts;
  }
Parse options passed in via an arguments array. Assumes that array has been split on
white-space and placed into a {@code Queue}. Any unknown arguments will remain in the queue at
the conclusion of this method call. It's up to the caller to deal with these unrecognized
arguments.
hbase-diagnostics/src/main/java/org/apache/hadoop/hbase/PerformanceEvaluation.java