Refactor DeviceLogReader

This commit is contained in:
John McCutchan
2016-03-07 13:52:27 -08:00
parent 0e675be6f9
commit 8803cecea1
6 changed files with 351 additions and 94 deletions

View File

@@ -10,20 +10,30 @@ import '../globals.dart';
typedef String StringConverter(String string);
/// This runs the command in the background from the specified working
/// directory. Completes when the process has been started.
Future<Process> runCommand(List<String> cmd, {String workingDirectory}) async {
printTrace(cmd.join(' '));
String executable = cmd[0];
List<String> arguments = cmd.length > 1 ? cmd.sublist(1) : [];
Process process = await Process.start(
executable,
arguments,
workingDirectory: workingDirectory
);
return process;
}
/// This runs the command and streams stdout/stderr from the child process to
/// this process' stdout/stderr.
/// this process' stdout/stderr. Completes with the process's exit code.
Future<int> runCommandAndStreamOutput(List<String> cmd, {
String workingDirectory,
String prefix: '',
RegExp filter,
StringConverter mapFunction
}) async {
printTrace(cmd.join(' '));
Process process = await Process.start(
cmd[0],
cmd.sublist(1),
workingDirectory: workingDirectory
);
Process process = await runCommand(cmd,
workingDirectory: workingDirectory);
process.stdout
.transform(UTF8.decoder)
.transform(const LineSplitter())