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.getArgumentsString();
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;
}
if(editedLine.charAt(0) == '"') {
if(editedLine.length() > 1 && editedLine.charAt(editedLine.length() - 1) == '"') {
editedLine = editedLine.substring(1, editedLine.length() - 1);
}
}
try {
BatchedCommand newCmd = ctx.toBatchedCommand(editedLine);
batch.set(lineNumber - 1, newCmd);
ctx.printLine("#" + lineNumber + " " + newCmd.getCommand());
} catch (CommandFormatException e) {
ctx.printLine("Failed to process command line '" + editedLine + "': " + e.getLocalizedMessage());
}
}