@Override
    public BatchedCommand toBatchedCommand(String line) throws OperationFormatException {

      if (line.isEmpty()) {
        throw new IllegalArgumentException("Null command line.");
      }

      final String originalCommand = this.cmd;
      final String originalArguments = this.parsedArgs.getArgumentsString();
      if (isOperation(line)) {
        try {
          setArgs(null, line);
          DefaultOperationRequestBuilder builder = new DefaultOperationRequestBuilder(getPrefix());
          parser.parse(line, builder);
          ModelNode request = builder.buildRequest();
          StringBuilder op = new StringBuilder();
          op.append(prefixFormatter.format(builder.getAddress()));
          op.append(line.substring(line.indexOf(':')));
          return new DefaultBatchedCommand(op.toString(), request);
        } finally {
          setArgs(originalCommand, originalArguments);
        }
      }

      String cmd = line;
      String cmdArgs = null;
      for (int i = 0; i < cmd.length(); ++i) {
        if (Character.isWhitespace(cmd.charAt(i))) {
          cmdArgs = cmd.substring(i + 1).trim();
          cmd = cmd.substring(0, i);
          break;
        }
      }

      CommandHandler handler = cmdRegistry.getCommandHandler(cmd.toLowerCase());
      if (handler == null) {
        throw new OperationFormatException("No command handler for '" + cmd + "'.");
      }
      if (!(handler instanceof OperationCommand)) {
        throw new OperationFormatException("The command is not allowed in a batch.");
      }

      try {
        setArgs(cmd, cmdArgs);
        ModelNode request = ((OperationCommand) handler).buildRequest(this);
        return new DefaultBatchedCommand(line, request);
      } finally {
        setArgs(originalCommand, originalArguments);
      }
    }
  protected Executable addNext(
      final String command,
      final SchemaCrawlerOptions schemaCrawlerOptions,
      final Config additionalConfiguration,
      final String outputFormat,
      final File outputFile)
      throws SchemaCrawlerException {
    try {
      final CommandRegistry commandRegistry = new CommandRegistry();
      final Executable executable = commandRegistry.instantiateExecutableForCommand(command);

      final OutputOptions outputOptions = new OutputOptions(outputFormat, outputFile);

      executable.setSchemaCrawlerOptions(schemaCrawlerOptions);
      executable.setAdditionalConfiguration(additionalConfiguration);
      executable.setOutputOptions(outputOptions);

      return addNext(executable);
    } catch (final Exception e) {
      throw new SchemaCrawlerException(
          String.format("Bad command, %s - %s - %s", command, outputFormat, outputFile));
    }
  }
  static {
    cmdRegistry.registerHandler(new HelpHandler(), "help", "h");
    cmdRegistry.registerHandler(new QuitHandler(), "quit", "q", "exit");
    cmdRegistry.registerHandler(new ConnectHandler(), "connect");
    cmdRegistry.registerHandler(new PrefixHandler(), "cd", "cn");
    cmdRegistry.registerHandler(new LsHandler(), "ls");
    cmdRegistry.registerHandler(new HistoryHandler(), "history");
    cmdRegistry.registerHandler(new DeployHandler(), "deploy");
    cmdRegistry.registerHandler(new UndeployHandler(), "undeploy");
    cmdRegistry.registerHandler(new PrintWorkingNodeHandler(), "pwd", "pwn");

    cmdRegistry.registerHandler(new CreateJmsQueueHandler(), "create-jms-queue");
    cmdRegistry.registerHandler(new DeleteJmsQueueHandler(), "delete-jms-queue");
    cmdRegistry.registerHandler(new CreateJmsTopicHandler(), "create-jms-topic");
    cmdRegistry.registerHandler(new DeleteJmsTopicHandler(), "delete-jms-topic");
    cmdRegistry.registerHandler(new CreateJmsCFHandler(), "create-jms-cf");
    cmdRegistry.registerHandler(new DeleteJmsCFHandler(), "delete-jms-cf");
    cmdRegistry.registerHandler(new CreateJmsResourceHandler(), false, "create-jms-resource");
    cmdRegistry.registerHandler(new DeleteJmsResourceHandler(), false, "delete-jms-resource");

    cmdRegistry.registerHandler(new BatchHandler(), "batch");
    cmdRegistry.registerHandler(new BatchDiscardHandler(), "discard-batch");
    cmdRegistry.registerHandler(new BatchListHandler(), "list-batch");
    cmdRegistry.registerHandler(new BatchHoldbackHandler(), "holdback-batch");
    cmdRegistry.registerHandler(new BatchRunHandler(), "run-batch");
    cmdRegistry.registerHandler(new BatchClearHandler(), "clear-batch");
    cmdRegistry.registerHandler(new BatchRemoveLineHandler(), "remove-batch-line");
    cmdRegistry.registerHandler(new BatchMoveLineHandler(), "move-batch-line");
    cmdRegistry.registerHandler(new BatchEditLineHandler(), "edit-batch-line");
  }
  protected static void processLine(final CommandContextImpl cmdCtx, String line) {
    if (line.isEmpty()) {
      return;
    }

    if (isOperation(line)) {
      cmdCtx.setArgs(null, line);
      if (cmdCtx.isBatchMode()) {
        DefaultOperationRequestBuilder builder =
            new DefaultOperationRequestBuilder(cmdCtx.getPrefix());
        try {
          cmdCtx.getOperationRequestParser().parse(line, builder);
          ModelNode request = builder.buildRequest();
          StringBuilder op = new StringBuilder();
          op.append(cmdCtx.getPrefixFormatter().format(builder.getAddress()));
          op.append(line.substring(line.indexOf(':')));
          DefaultBatchedCommand batchedCmd = new DefaultBatchedCommand(op.toString(), request);
          Batch batch = cmdCtx.getBatchManager().getActiveBatch();
          batch.add(batchedCmd);
          cmdCtx.printLine("#" + batch.size() + " " + batchedCmd.getCommand());
        } catch (CommandFormatException e) {
          cmdCtx.printLine(e.getLocalizedMessage());
        }
      } else {
        cmdCtx.operationHandler.handle(cmdCtx);
      }

    } else {
      String cmd = line;
      String cmdArgs = null;
      for (int i = 0; i < cmd.length(); ++i) {
        if (Character.isWhitespace(cmd.charAt(i))) {
          cmdArgs = cmd.substring(i + 1).trim();
          cmd = cmd.substring(0, i);
          break;
        }
      }
      cmdCtx.setArgs(cmd, cmdArgs);

      CommandHandler handler = cmdRegistry.getCommandHandler(cmd.toLowerCase());
      if (handler != null) {
        if (cmdCtx.isBatchMode() && handler.isBatchMode()) {
          if (!(handler instanceof OperationCommand)) {
            cmdCtx.printLine("The command is not allowed in a batch.");
          } else {
            try {
              ModelNode request = ((OperationCommand) handler).buildRequest(cmdCtx);
              BatchedCommand batchedCmd = new DefaultBatchedCommand(line, request);
              Batch batch = cmdCtx.getBatchManager().getActiveBatch();
              batch.add(batchedCmd);
              cmdCtx.printLine("#" + batch.size() + " " + batchedCmd.getCommand());
            } catch (OperationFormatException e) {
              cmdCtx.printLine("Failed to add to batch: " + e.getLocalizedMessage());
            }
          }
        } else {
          handler.handle(cmdCtx);
        }
      } else {
        cmdCtx.printLine(
            "Unexpected command '" + line + "'. Type 'help' for the list of supported commands.");
      }
    }
    cmdCtx.setArgs(null, null);
  }