Search in sources :

Example 1 with BatchManager

use of org.jboss.as.cli.batch.BatchManager in project wildfly-core by wildfly.

the class DeployArchiveCommand method discardBatch.

static void discardBatch(CommandContext ctx, String holdbackBatch, Attachments attachments, Consumer<Attachments> listener) {
    BatchManager batchManager = ctx.getBatchManager();
    // Get the files attached by the CLI script.
    // Must then add them to the passed attachemnts if non null.
    // If null, then we should have an heldback batch to which we need to add them
    Attachments archiveAttachments = batchManager.getActiveBatch().getAttachments();
    if (attachments != null) {
        for (String f : archiveAttachments.getAttachedFiles()) {
            attachments.addFileAttachment(f);
        }
    }
    batchManager.discardActiveBatch();
    if (holdbackBatch != null) {
        batchManager.activateHeldbackBatch(holdbackBatch);
        Attachments activeAttachments = batchManager.getActiveBatch().getAttachments();
        // that have been transfered when creating the archive batch.
        for (int i = activeAttachments.getAttachedFiles().size(); i < archiveAttachments.getAttachedFiles().size(); i++) {
            activeAttachments.addFileAttachment(archiveAttachments.getAttachedFiles().get(i));
        }
        activeAttachments.addConsumer(listener);
    }
}
Also used : BatchManager(org.jboss.as.cli.batch.BatchManager) Attachments(org.jboss.as.cli.Attachments)

Example 2 with BatchManager

use of org.jboss.as.cli.batch.BatchManager in project wildfly-core by wildfly.

the class BatchEditLineHandler method doHandle.

/* (non-Javadoc)
     * @see org.jboss.as.cli.handlers.CommandHandlerWithHelp#doHandle(org.jboss.as.cli.CommandContext)
     */
@Override
protected void doHandle(CommandContext ctx) throws CommandFormatException {
    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());
}
Also used : Batch(org.jboss.as.cli.batch.Batch) CommandFormatException(org.jboss.as.cli.CommandFormatException) BatchManager(org.jboss.as.cli.batch.BatchManager) BatchedCommand(org.jboss.as.cli.batch.BatchedCommand)

Example 3 with BatchManager

use of org.jboss.as.cli.batch.BatchManager in project wildfly-core by wildfly.

the class BatchListHandler method doHandle.

/* (non-Javadoc)
     * @see org.jboss.as.cli.handlers.CommandHandlerWithHelp#doHandle(org.jboss.as.cli.CommandContext)
     */
@Override
protected void doHandle(CommandContext ctx) throws CommandFormatException {
    BatchManager batchManager = ctx.getBatchManager();
    if (!batchManager.isBatchActive()) {
        throw new CommandFormatException("No active batch.");
    }
    Batch activeBatch = batchManager.getActiveBatch();
    List<BatchedCommand> commands = activeBatch.getCommands();
    if (!commands.isEmpty()) {
        for (int i = 0; i < commands.size(); ++i) {
            BatchedCommand cmd = commands.get(i);
            ctx.printLine("#" + (i + 1) + ' ' + cmd.getCommand());
        }
    } else {
        ctx.printLine("The batch is empty.");
    }
}
Also used : Batch(org.jboss.as.cli.batch.Batch) CommandFormatException(org.jboss.as.cli.CommandFormatException) BatchManager(org.jboss.as.cli.batch.BatchManager) BatchedCommand(org.jboss.as.cli.batch.BatchedCommand)

Example 4 with BatchManager

use of org.jboss.as.cli.batch.BatchManager in project wildfly-core by wildfly.

the class BatchMoveLineHandler method doHandle.

/* (non-Javadoc)
     * @see org.jboss.as.cli.handlers.CommandHandlerWithHelp#doHandle(org.jboss.as.cli.CommandContext)
     */
@Override
protected void doHandle(CommandContext ctx) throws CommandFormatException {
    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.");
    }
    List<String> arguments = ctx.getParsedCommandLine().getOtherProperties();
    if (arguments.isEmpty()) {
        throw new CommandFormatException("Missing line number.");
    }
    if (arguments.size() != 2) {
        throw new CommandFormatException("Expected two arguments but received: " + arguments);
    }
    String intStr = arguments.get(0);
    final 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 + "].");
    }
    intStr = arguments.get(1);
    final int toLineNumber;
    try {
        toLineNumber = Integer.parseInt(intStr);
    } catch (NumberFormatException e) {
        throw new CommandFormatException("Failed to parse line number '" + intStr + "': " + e.getLocalizedMessage());
    }
    if (toLineNumber < 1 || toLineNumber > batchSize) {
        throw new CommandFormatException(toLineNumber + " isn't in range [1.." + batchSize + "].");
    }
    batch.move(lineNumber - 1, toLineNumber - 1);
}
Also used : Batch(org.jboss.as.cli.batch.Batch) CommandFormatException(org.jboss.as.cli.CommandFormatException) BatchManager(org.jboss.as.cli.batch.BatchManager)

Example 5 with BatchManager

use of org.jboss.as.cli.batch.BatchManager in project wildfly-core by wildfly.

the class BatchRemoveLineHandler method doHandle.

/* (non-Javadoc)
     * @see org.jboss.as.cli.handlers.CommandHandlerWithHelp#doHandle(org.jboss.as.cli.CommandContext)
     */
@Override
protected void doHandle(CommandContext ctx) throws CommandFormatException {
    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.");
    }
    List<String> arguments = ctx.getParsedCommandLine().getOtherProperties();
    if (arguments.isEmpty()) {
        throw new CommandFormatException("Missing line number.");
    }
    if (arguments.size() != 1) {
        throw new CommandFormatException("Expected only one argument - the line number but received: " + arguments);
    }
    String intStr = arguments.get(0);
    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 + "].");
    }
    batch.remove(lineNumber - 1);
}
Also used : Batch(org.jboss.as.cli.batch.Batch) CommandFormatException(org.jboss.as.cli.CommandFormatException) BatchManager(org.jboss.as.cli.batch.BatchManager)

Aggregations

BatchManager (org.jboss.as.cli.batch.BatchManager)18 CommandFormatException (org.jboss.as.cli.CommandFormatException)10 Batch (org.jboss.as.cli.batch.Batch)7 BatchedCommand (org.jboss.as.cli.batch.BatchedCommand)4 ParsedCommandLine (org.jboss.as.cli.operation.ParsedCommandLine)3 BufferedReader (java.io.BufferedReader)2 File (java.io.File)2 FileReader (java.io.FileReader)2 IOException (java.io.IOException)2 Attachments (org.jboss.as.cli.Attachments)2 CommandLineException (org.jboss.as.cli.CommandLineException)2 ArrayList (java.util.ArrayList)1 ModelNode (org.jboss.dmr.ModelNode)1