Package org.jboss.as.cli.batch

Examples of org.jboss.as.cli.batch.Batch


                    lineNumber = Integer.parseInt(lineNumberStr);
                } catch(NumberFormatException e) {
                    return -1;
                }

                final Batch batch = batchManager.getActiveBatch();
                int batchSize = batch.size();

                if(lineNumber < 1 || lineNumber > batchSize) {
                    return -1;
                }

                nextCharIndex = nextWsIndex + 1;
                while (nextCharIndex < buffer.length()) {
                    if (!Character.isWhitespace(buffer.charAt(nextCharIndex))) {
                        break;
                    }
                    ++nextCharIndex;
                }

                String cmd = buffer.substring(nextCharIndex);
                if("--help".startsWith(cmd)) {
                    candidates.add("--help");
                }

                int cmdResult = ctx.getDefaultCommandCompleter().complete(ctx, cmd, 0, candidates);

                final String batchedCmd = batch.getCommands().get(lineNumber - 1).getCommand();
                if(cmd.isEmpty() || batchedCmd.startsWith(cmd)) {
                    int lastWsIndex = cmd.lastIndexOf(' ');
                    if(lastWsIndex > 0) {
                        candidates.add(batchedCmd.substring(lastWsIndex + 1).trim());
                    } else {
View Full Code Here


        if(!batchManager.isBatchActive()) {
            ctx.printLine("No active batch.");
            return;
        }

        Batch batch = batchManager.getActiveBatch();
        final int batchSize = batch.size();
        if(batchSize == 0) {
            ctx.printLine("The batch is empty.");
            return;
        }

        String argsStr = ctx.getCommandArguments();
        if(argsStr == null) {
            ctx.printLine("Missing line number.");
            return;
        }

        int i = 0;
        while(i < argsStr.length()) {
            if(Character.isWhitespace(argsStr.charAt(i))) {
                break;
            }
            ++i;
        }

        if(i == argsStr.length()) {
            ctx.printLine("Missing the new command line after the index.");
            return;
        }

        String intStr = argsStr.substring(0, i);
        int lineNumber;
        try {
            lineNumber = Integer.parseInt(intStr);
        } catch(NumberFormatException e) {
            ctx.printLine("Failed to parse line number '" + intStr + "': " + e.getLocalizedMessage());
            return;
        }

        if(lineNumber < 1 || lineNumber > batchSize) {
            ctx.printLine(lineNumber + " isn't in range [1.." + batchSize + "].");
            return;
        }

        String editedLine = argsStr.substring(i).trim();
        if(editedLine.length() == 0) {
            ctx.printLine("Missing the new command line after the index.");
            return;
        }

        try {
            BatchedCommand newCmd = ctx.toBatchedCommand(editedLine);
            batch.set(lineNumber - 1, newCmd);
        } catch (OperationFormatException e) {
            ctx.printLine("Failed to process command line '" + editedLine + "': " + e.getLocalizedMessage());
        }
    }
View Full Code Here

        if(!batchManager.isBatchActive()) {
            ctx.printLine("No active batch.");
            return;
        }

        Batch batch = batchManager.getActiveBatch();
        final int batchSize = batch.size();
        if(batchSize == 0) {
            ctx.printLine("The batch is empty.");
            return;
        }

        List<String> arguments = ctx.getArguments();
        if(arguments.isEmpty()) {
            ctx.printLine("Missing line number.");
            return;
        }

        if(arguments.size() != 2) {
            ctx.printLine("Expected two arguments but received: " + arguments);
            return;
        }

        String intStr = arguments.get(0);
        final int lineNumber;
        try {
            lineNumber = Integer.parseInt(intStr);
        } catch(NumberFormatException e) {
            ctx.printLine("Failed to parse line number '" + intStr + "': " + e.getLocalizedMessage());
            return;
        }

        if(lineNumber < 1 || lineNumber > batchSize) {
            ctx.printLine(lineNumber + " isn't in range [1.." + batchSize + "].");
            return;
        }

        intStr = arguments.get(1);
        final int toLineNumber;
        try {
            toLineNumber = Integer.parseInt(intStr);
        } catch(NumberFormatException e) {
            ctx.printLine("Failed to parse line number '" + intStr + "': " + e.getLocalizedMessage());
            return;
        }

        if(toLineNumber < 1 || toLineNumber > batchSize) {
            ctx.printLine(toLineNumber + " isn't in range [1.." + batchSize + "].");
            return;
        }

        batch.move(lineNumber - 1, toLineNumber - 1);
    }
View Full Code Here

        if(!batchManager.isBatchActive()) {
            ctx.printLine("No active batch.");
            return;
        }

        Batch batch = batchManager.getActiveBatch();
        List<BatchedCommand> currentBatch = batch.getCommands();
        if(currentBatch.isEmpty()) {
            ctx.printLine("The batch is empty.");
            batchManager.discardActiveBatch();
            return;
        }
View Full Code Here

                    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;
                }
            }

            CommandHandler handler = cmdRegistry.getCommandHandler(cmd.toLowerCase());
            if(handler != null) {
                cmdCtx.setArgs(cmd, cmdArgs, handler);

                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 (CommandFormatException e) {
                            cmdCtx.printLine("Failed to add to batch: " + e.getLocalizedMessage());
                        }
                    }
                } else {
View Full Code Here

            if(cmdCtx.isBatchMode()) {
                StringBuilder op = new StringBuilder();
                op.append(cmdCtx.getPrefixFormatter().format(cmdCtx.parsedCmd.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());
            } else {
                cmdCtx.set("OP_REQ", request);
                try {
                    cmdCtx.operationHandler.handle(cmdCtx);
                } finally {
                    cmdCtx.set("OP_REQ", null);
                }
            }

        } else {
            try {
                cmdCtx.resetArgs(line);
            } catch (CommandFormatException e1) {
                cmdCtx.printLine(e1.getLocalizedMessage());
                return;
            }

            final String cmdName = cmdCtx.parsedCmd.getOperationName();
            CommandHandler handler = cmdRegistry.getCommandHandler(cmdName.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 (CommandFormatException e) {
                            cmdCtx.printLine("Failed to add to batch: " + e.getLocalizedMessage());
                        }
                    }
                } else {
View Full Code Here

        BatchManager batchManager = ctx.getBatchManager();
        if(!batchManager.isBatchActive()) {
            throw new CommandFormatException("No active batch.");
        }

        Batch batch = batchManager.getActiveBatch();
        final int batchSize = batch.size();
        if(batchSize == 0) {
            throw new CommandFormatException("The batch is empty.");
        }

        String argsStr = ctx.getArgumentsString();
        if(argsStr == null) {
            throw new CommandFormatException("Missing line number.");
        }

        int i = 0;
        while(i < argsStr.length()) {
            if(Character.isWhitespace(argsStr.charAt(i))) {
                break;
            }
            ++i;
        }

        if(i == argsStr.length()) {
            throw new CommandFormatException("Missing the new command line after the index.");
        }

        String intStr = argsStr.substring(0, i);
        int lineNumber;
        try {
            lineNumber = Integer.parseInt(intStr);
        } catch(NumberFormatException e) {
            throw new CommandFormatException("Failed to parse line number '" + intStr + "': " + e.getLocalizedMessage());
        }

        if(lineNumber < 1 || lineNumber > batchSize) {
            throw new CommandFormatException(lineNumber + " isn't in range [1.." + batchSize + "].");
        }

        String editedLine = argsStr.substring(i).trim();
        if(editedLine.length() == 0) {
            throw new CommandFormatException("Missing the new command line after the index.");
        }

        if(editedLine.charAt(0) == '"') {
            if(editedLine.length() > 1 && editedLine.charAt(editedLine.length() - 1) == '"') {
                editedLine = editedLine.substring(1, editedLine.length() - 1);
            }
        }

        BatchedCommand newCmd = ctx.toBatchedCommand(editedLine);
        batch.set(lineNumber - 1, newCmd);
        ctx.printLine("#" + lineNumber + " " + newCmd.getCommand());
    }
View Full Code Here

                if (isBatchMode()) {
                    StringBuilder op = new StringBuilder();
                    op.append(getNodePathFormatter().format(parsedCmd.getAddress()));
                    op.append(line.substring(line.indexOf(':')));
                    DefaultBatchedCommand batchedCmd = new DefaultBatchedCommand(op.toString(), request);
                    Batch batch = getBatchManager().getActiveBatch();
                    batch.add(batchedCmd);
                    printLine("#" + batch.size() + " " + batchedCmd.getCommand());
                } else {
                    set("OP_REQ", request);
                    try {
                        operationHandler.handle(this);
                    } finally {
                        set("OP_REQ", null);
                    }
                }
            } else {
                final String cmdName = parsedCmd.getOperationName();
                CommandHandler handler = cmdRegistry.getCommandHandler(cmdName.toLowerCase());
                if (handler != null) {
                    if (isBatchMode() && handler.isBatchMode(this)) {
                        if (!(handler instanceof OperationCommand)) {
                            throw new CommandLineException("The command is not allowed in a batch.");
                        } else {
                            try {
                                ModelNode request = ((OperationCommand) handler).buildRequest(this);
                                BatchedCommand batchedCmd = new DefaultBatchedCommand(line, request);
                                Batch batch = getBatchManager().getActiveBatch();
                                batch.add(batchedCmd);
                                printLine("#" + batch.size() + " " + batchedCmd.getCommand());
                            } catch (CommandFormatException e) {
                                throw new CommandFormatException("Failed to add to batch '" + line + "'", e);
                            }
                        }
                    } else {
View Full Code Here

                    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;
                }
            }

            CommandHandler handler = cmdRegistry.getCommandHandler(cmd.toLowerCase());
            if(handler != null) {
                cmdCtx.setArgs(cmd, cmdArgs, handler);

                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 (CommandFormatException e) {
                            cmdCtx.printLine("Failed to add to batch: " + e.getLocalizedMessage());
                        }
                    }
                } else {
View Full Code Here

        if(!batchManager.isBatchActive()) {
            ctx.printLine("No active batch.");
            return;
        }

        Batch batch = batchManager.getActiveBatch();
        final int batchSize = batch.size();
        if(batchSize == 0) {
            ctx.printLine("The batch is empty.");
            return;
        }

        List<String> arguments = ctx.getParsedArguments().getOtherArguments();
        if(arguments.isEmpty()) {
            ctx.printLine("Missing line number.");
            return;
        }

        if(arguments.size() != 1) {
            ctx.printLine("Expected only one argument - the line number but received: " + arguments);
            return;
        }

        String intStr = arguments.get(0);
        int lineNumber;
        try {
            lineNumber = Integer.parseInt(intStr);
        } catch(NumberFormatException e) {
            ctx.printLine("Failed to parse line number '" + intStr + "': " + e.getLocalizedMessage());
            return;
        }

        if(lineNumber < 1 || lineNumber > batchSize) {
            ctx.printLine(lineNumber + " isn't in range [1.." + batchSize + "].");
            return;
        }

        batch.remove(lineNumber - 1);
    }
View Full Code Here

TOP

Related Classes of org.jboss.as.cli.batch.Batch

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.