runCmd function

Future<ProcessResult> runCmd(
  1. ProcessCmd cmd,
  2. {bool verbose,
  3. bool commandVerbose,
  4. Stream<List<int>> stdin,
  5. StreamSink<List<int>> stdout,
  6. StreamSink<List<int>> stderr}
)

Command runner

Execute a predefined ProcessCmd command

if commandVerbose is true, it writes the command line executed preceeded by $ to stdout. It streams stdout/error if verbose is true. verbose implies commandVerbose

Implementation

///
/// Execute a predefined ProcessCmd command
///
/// if [commandVerbose] is true, it writes the command line executed preceeded by $ to stdout. It streams
/// stdout/error if [verbose] is true.
/// [verbose] implies [commandVerbose]
///
Future<ProcessResult> runCmd(ProcessCmd cmd,
    {bool verbose,
    bool commandVerbose,
    Stream<List<int>> stdin,
    StreamSink<List<int>> stdout,
    StreamSink<List<int>> stderr}) async {
  if (verbose == true) {
    stdout ??= io.stdout;
    stderr ??= io.stderr;
    commandVerbose ??= true;
  }

  if (commandVerbose == true) {
    streamSinkWriteln(stdout ?? io.stdout, '\$ ${cmd}');
  }

  try {
    return await run(
      cmd.executable,
      cmd.arguments,
      workingDirectory: cmd.workingDirectory,
      environment: cmd.environment,
      includeParentEnvironment: cmd.includeParentEnvironment,
      runInShell: cmd.runInShell,
      stdoutEncoding: cmd.stdoutEncoding,
      stderrEncoding: cmd.stderrEncoding,
      //verbose: verbose,
      //commandVerbose: commandVerbose,
      stdin: stdin,
      stdout: stdout,
      stderr: stderr,
    );
  } catch (e) {
    if (verbose == true) {
      io.stderr.writeln(e);
      io.stderr.writeln('\$ ${cmd}');
      io.stderr.writeln(
          'workingDirectory: ${cmd.workingDirectory ?? Directory.current?.path}');
    }
    rethrow;
  }
}