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);
}
}
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());
}
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.");
}
}
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);
}
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);
}
Aggregations