run method

Future<List<CommandResult>> run({
  1. required bool bail,
  2. String label = 'Running ',
})

Implementation

Future<List<CommandResult>> run({
  required bool bail,
  String label = 'Running ',
}) async {
  final runner = _run(
    commands,
    bail: bail,
  );

  final results = <CommandResult>[];

  logger.write('\n');

  String getLabel() {
    Iterable<String> create() sync* {
      yield label.trim();
      yield ' ';
      yield darkGray.wrap('| ')!;
      yield magenta.wrap('${results.length}/${commands.length}')!;
    }

    return create().join();
  }

  final done = logger.progress(getLabel());

  await for (final result in runner) {
    results.add(result);
    if (result.exitCodeReason != ExitCode.success && bail) {
      break;
    }

    if (results.length < commands.length) {
      done.update(getLabel());
    } else {
      done.update(getLabel());
      break;
    }
  }

  if (results.any((e) => e.exitCodeReason != ExitCode.success)) {
    done.fail();
  } else {
    done.complete();
  }

  return results;
}