runTasksWithSpinner method

Future<void> runTasksWithSpinner(
  1. List<CommandTask> tasks
)

Run tasks with a spinner animation

Implementation

Future<void> runTasksWithSpinner(List<CommandTask> tasks) async {
  for (int i = 0; i < tasks.length; i++) {
    final task = tasks[i];
    final spinner = ConsoleSpinner('${task.name}...');
    spinner.start();

    try {
      await task.action();
      spinner.stop(
        completionMessage: '${task.name} completed',
        success: true,
      );
    } catch (e) {
      spinner.stop(
        completionMessage: '${task.name} failed: $e',
        success: false,
      );
      if (task.stopOnError) {
        rethrow;
      }
    }
  }
}