configure method

  1. @override
Step configure()
override

Composes Steps into one unit to enable more modular and understandable workflows.

Has to return a Step.

Implementation

@override
Step configure() => Runnable(name: name, (context) async {
  final process = await getProcess();
  /*
   * We have to await both futures at once with the list.
   */
  final List<Future<void>> futures = [];
  process.stdout.listen((chars) {
    if (onStdout != null) {
      futures.add(Future.value(onStdout!(context, chars)));
    }
  });
  /*
   * A full string is built for the response.
   */
  String fullStderr = "";
  process.stderr.listen((chars) {
    if (onStderr != null) {
      futures.add(Future.value(onStderr!(context, chars)));
    }
    fullStderr += "\n${String.fromCharCodes(chars)}";
  });

  /*
   * Await the process to be completed.
   * Then awaits only the futures (The actions of the stdout & stderr are already done).
   */
  await process.exitCode;
  await Future.wait(futures);

  if (runAsAdministrator && Platform.isWindows) {
    await _windowsWaitForPowershell();
  }
  context.send(
    Response(
      fullStderr.isNotEmpty
          ? "An error occurred in the process: $fullStderr"
          : "Shell step executed without any issues.",
      Level.verbose,
    ),
  );
});