runCommands method

Future<ExitCode> runCommands(
  1. Iterable<CommandToRun> commandsToRun, {
  2. required bool runConcurrently,
  3. required bool bail,
})

Implementation

Future<ExitCode> runCommands(
  Iterable<CommandToRun> commandsToRun, {
  required bool runConcurrently,
  required bool bail,
}) async {
  if (runConcurrently) {
    for (final command in commandsToRun) {
      logger.detail('Script: ${darkGray.wrap(command.command)}');
    }

    final runMany = RunManyScripts(
      commands: commandsToRun,
      bindings: bindings,
      logger: logger,
    );

    final exitCodes = await runMany.run(
      label: 'Running tests ',
      bail: bail,
    );

    exitCodes.printErrors(commandsToRun, logger);

    return exitCodes.exitCode(logger);
  }

  ExitCode? exitCode;

  for (final command in commandsToRun) {
    logger.detail(command.command);
    final scriptRunner = RunOneScript(
      command: command,
      bindings: bindings,
      logger: logger,
      showOutput: true,
    );

    final stopwatch = Stopwatch()..start();

    logger.info(darkGray.wrap(command.label));

    final result = await scriptRunner.run();

    final time = (stopwatch..stop()).format();

    logger
      ..info('Finished in ${cyan.wrap(time)}')
      ..write('\n');

    if (result.exitCodeReason != ExitCode.success) {
      exitCode = result.exitCodeReason;

      if (bail) {
        return exitCode;
      }
    }
  }

  return exitCode ?? ExitCode.success;
}