Add remaining args to spawnX. (#29)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 3dc176d..69ab12b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -14,6 +14,10 @@
}
```
+- Added the remaining missing arguments to `ProcessManager.spawnX` which
+ forward to `Process.start`. It is now an interchangeable function for running
+ a process.
+
## 0.3.0
- **BREAKING CHANGE**: The `arguments` argument to `ProcessManager.spawn` is
diff --git a/lib/io.dart b/lib/io.dart
index e18dcac..3ad63fa 100644
--- a/lib/io.dart
+++ b/lib/io.dart
@@ -4,6 +4,6 @@
export 'src/exit_code.dart' show ExitCode;
export 'src/permissions.dart' show isExecutable;
-export 'src/process_manager.dart' show ProcessManager, Spawn;
+export 'src/process_manager.dart' show ProcessManager, Spawn, StartProcess;
export 'src/shared_stdin.dart' show SharedStdIn, sharedStdIn;
export 'src/shell_words.dart' show shellSplit;
diff --git a/lib/src/process_manager.dart b/lib/src/process_manager.dart
index 5a796d8..5a14f58 100644
--- a/lib/src/process_manager.dart
+++ b/lib/src/process_manager.dart
@@ -9,6 +9,19 @@
import 'shared_stdin.dart';
+/// Type definition for both [io.Process.start] and [ProcessManager.spawn].
+///
+/// Useful for taking different implementations of this base functionality.
+typedef Future<io.Process> StartProcess(
+ String executable,
+ Iterable<String> arguments, {
+ String workingDirectory,
+ Map<String, String> environment,
+ bool includeParentEnvironment,
+ bool runInShell,
+ io.ProcessStartMode mode,
+});
+
/// A high-level abstraction around using and managing processes on the system.
abstract class ProcessManager {
/// Terminates the global `stdin` listener, making future listens impossible.
@@ -53,9 +66,22 @@
/// Returns a future that completes with a handle to the spawned process.
Future<io.Process> spawn(
String executable,
- Iterable<String> arguments,
- ) async {
- final process = io.Process.start(executable, arguments.toList());
+ Iterable<String> arguments, {
+ String workingDirectory,
+ Map<String, String> environment,
+ bool includeParentEnvironment: true,
+ bool runInShell: false,
+ io.ProcessStartMode mode: io.ProcessStartMode.NORMAL,
+ }) async {
+ final process = io.Process.start(
+ executable,
+ arguments.toList(),
+ workingDirectory: workingDirectory,
+ environment: environment,
+ includeParentEnvironment: includeParentEnvironment,
+ runInShell: runInShell,
+ mode: mode,
+ );
return new _ForwardingSpawn(await process, _stdin, _stdout, _stderr);
}
@@ -68,9 +94,22 @@
/// Returns a future that completes with a handle to the spawned process.
Future<io.Process> spawnBackground(
String executable,
- Iterable<String> arguments,
- ) async {
- final process = io.Process.start(executable, arguments.toList());
+ Iterable<String> arguments, {
+ String workingDirectory,
+ Map<String, String> environment,
+ bool includeParentEnvironment: true,
+ bool runInShell: false,
+ io.ProcessStartMode mode: io.ProcessStartMode.NORMAL,
+ }) async {
+ final process = io.Process.start(
+ executable,
+ arguments.toList(),
+ workingDirectory: workingDirectory,
+ environment: environment,
+ includeParentEnvironment: includeParentEnvironment,
+ runInShell: runInShell,
+ mode: mode,
+ );
return new _ForwardingSpawn(
await process,
const Stream.empty(),
@@ -86,9 +125,22 @@
/// Returns a future that completes with a handle to the spawned process.
Future<io.Process> spawnDetached(
String executable,
- Iterable<String> arguments,
- ) async {
- return io.Process.start(executable, arguments.toList());
+ Iterable<String> arguments, {
+ String workingDirectory,
+ Map<String, String> environment,
+ bool includeParentEnvironment: true,
+ bool runInShell: false,
+ io.ProcessStartMode mode: io.ProcessStartMode.NORMAL,
+ }) async {
+ return io.Process.start(
+ executable,
+ arguments.toList(),
+ workingDirectory: workingDirectory,
+ environment: environment,
+ includeParentEnvironment: includeParentEnvironment,
+ runInShell: runInShell,
+ mode: mode,
+ );
}
}
diff --git a/test/process_manager_test.dart b/test/process_manager_test.dart
index 88e63af..0503a9f 100644
--- a/test/process_manager_test.dart
+++ b/test/process_manager_test.dart
@@ -18,6 +18,15 @@
List<String> stdoutLog;
List<String> stderrLog;
+ test('spawn functions should match the type definition of Process.start', () {
+ final isStartProcess = const isInstanceOf<StartProcess>();
+ expect(Process.start, isStartProcess);
+ final manager = new ProcessManager();
+ expect(manager.spawn, isStartProcess);
+ expect(manager.spawnBackground, isStartProcess);
+ expect(manager.spawnDetached, isStartProcess);
+ });
+
group('spawn', () {
setUp(() async {
fakeStdIn = new StreamController<String>(sync: true);