예제 #1
0
  @Override
  protected void doHandle(CommandContext ctx) {

    ParsedArguments args = ctx.getParsedArguments();
    if (!args.hasArguments()) {
      printHistory(ctx);
      return;
    }

    if (clear.isPresent(args)) {
      ctx.getHistory().clear();
    } else if (disable.isPresent(args)) {
      ctx.getHistory().setUseHistory(false);
    } else if (enable.isPresent(args)) {
      ctx.getHistory().setUseHistory(true);
    } else {
      ctx.printLine("Unexpected argument '" + ctx.getArgumentsString() + '\'');
    }
  }
예제 #2
0
  /* (non-Javadoc)
   * @see org.jboss.as.cli.handlers.CommandHandlerWithHelp#doHandle(org.jboss.as.cli.CommandContext)
   */
  @Override
  protected void doHandle(CommandContext ctx) throws CommandLineException {

    String argsStr = ctx.getArgumentsString();
    if (argsStr == null) {
      throw new CommandFormatException("The command is missing arguments.");
    }

    final BatchManager batchManager = ctx.getBatchManager();
    if (batchManager.isBatchActive()) {
      throw new CommandFormatException("if is not allowed while in batch mode.");
    }

    final ParsedCommandLine args = ctx.getParsedCommandLine();
    final String conditionStr = this.condition.getValue(args, true);
    int i = argsStr.indexOf(conditionStr);
    if (i < 0) {
      throw new CommandFormatException(
          "Failed to locate '" + conditionStr + "' in '" + argsStr + "'");
    }
    i = argsStr.indexOf("of", i + conditionStr.length());
    if (i < 0) {
      throw new CommandFormatException("Failed to locate 'of' in '" + argsStr + "'");
    }

    final String line = argsStr.substring(i + 2);
    try {
      IfElseBlock.create(ctx).setCondition(conditionStr, ctx.buildRequest(line));
    } catch (CommandLineException e) {
      IfElseBlock.remove(ctx);
      throw e;
    }

    if (!batchManager.activateNewBatch()) {
      IfElseBlock.remove(ctx);
      // that's more like illegal state
      throw new CommandFormatException("Failed to activate batch mode for if.");
    }
  }