runCommand method
Runs a list of contiguous UndoableCommand and return an exit code If one command throws an Exception they will all be undone by calling the undo Function in UndoableCommand
Implementation
FutureOr<int> runCommand(List<UndoableCommand> commands) async {
debugPrintToConsole(message: "Executing ${commands.length} commands");
int i = 0;
try {
while (i < commands.length) {
UndoableCommand c = commands[i++];
debugPrintToConsole(
message: "Executing $i: ${c.runtimeType}",
);
await c.execute();
}
return 0;
} catch (e, trace) {
if (!isVerboseMode) {
printToConsole(
message: "An error has occurred. Run with -${CliCommandOptionsEnum.verbose.abbreviation} to see more details",
color: CliColor.red,
);
}
if (e is FileSystemException) {
onFileSystemException(e);
} else {
debugPrintToConsole(message: e.toString(), color: CliColor.red);
}
debugPrintToConsole(message: trace.toString(), color: CliColor.red);
while (i > 0) {
UndoableCommand c = commands[--i];
debugPrintToConsole(
message: "Undoing $i: ${c.runtimeType}",
);
await c.undo();
}
return 1;
}
}