start method

Future<int> start({
  1. String? workingDirectory,
  2. void progressOut(
    1. String line
    )?,
  3. void progressErr(
    1. String line
    )?,
  4. bool showLog = true,
})

Implementation

Future<int> start({
  String? workingDirectory,
  void Function(String line)? progressOut,
  void Function(String line)? progressErr,
  bool showLog = true,
}) async {
  final commandCli = CommandlineConverter().convert(this);

  final executable = commandCli.first;
  final arguments = commandCli.sublist(1);

  final process = await Process.start(
    executable,
    arguments,
    runInShell: true,
    workingDirectory: workingDirectory,
    environment: Platform.environment,
  );

  process.stdout.transform(utf8.decoder).listen(((line) {
    progressOut?.call(line);
    if (showLog) stdout.write(line);
  }));

  process.stderr.transform(utf8.decoder).listen(((line) {
    progressErr?.call(line);
    if (showLog) stderr.write(line);
  }));

  final exitCode = await process.exitCode;

  if (exitCode > 0) {
    StatusHelper.failed('$this has exit with code $exitCode',
        statusExit: exitCode);
  }
  return exitCode;
}