You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix documentation throughout the codebase and enforce that all public symbols have documentation. (#163)
* Fix documentation throughout the codebase and enforce that all public symbols have documentation.
* Apply documetation suggestions from code review
Co-authored-by: Joseph Heck <[email protected]>
* Disable AllPublicDeclarationsHaveDocumentation because it's too excessive
* Use fatalError() for no-op methods
---------
Co-authored-by: Joseph Heck <[email protected]>
Then, adding the `Subprocess` module to your target dependencies:
18
+
Then, add the `Subprocess` module to your target dependencies:
19
19
20
20
```swift
21
21
.target(
@@ -29,27 +29,27 @@ Then, adding the `Subprocess` module to your target dependencies:
29
29
`Subprocess` offers two [package traits](https://github.com/swiftlang/swift-evolution/blob/main/proposals/0450-swiftpm-package-traits.md):
30
30
31
31
-`SubprocessFoundation`: includes a dependency on `Foundation` and adds extensions on Foundation types like `Data`. This trait is enabled by default.
32
-
-`SubprocessSpan`: makes Subprocess’ API, mainly `OutputProtocol`, `RawSpan`based. This trait is enabled whenever `RawSpan` is available and should only be disabled when `RawSpan` is not available.
32
+
-`SubprocessSpan`: makes Subprocess's API, mainly `OutputProtocol`, `RawSpan`-based. This trait is enabled whenever `RawSpan` is available and should only be disabled when `RawSpan` is not available.
33
33
34
34
Please find the API proposal [here](https://github.com/swiftlang/swift-foundation/blob/main/Proposals/0007-swift-subprocess.md).
35
35
36
36
### Swift Versions
37
37
38
-
The minimal supported Swift version is **Swift 6.1**.
38
+
The minimum supported Swift version is **Swift 6.1**.
39
39
40
40
To experiment with the `SubprocessSpan` trait, Swift 6.2 is required. Currently, you can download the Swift 6.2 toolchain (`main` development snapshot) [here](https://www.swift.org/install/macos/#development-snapshots).
41
41
42
42
43
43
## Feature Overview
44
44
45
-
### Run and Asynchonously Collect Output
45
+
### Run and Asynchronously Collect Output
46
46
47
47
The easiest way to spawn a process with `Subprocess` is to simply run it and await its `CollectedResult`:
48
48
49
49
```swift
50
50
importSubprocess
51
51
52
-
let result =tryawaitrun(.name("ls"))
52
+
let result =tryawaitrun(.name("ls"), output: .string(limit: 4096))
53
53
54
54
print(result.processIdentifier) // prints 1234
55
55
print(result.terminationStatus) // prints exited(0)
@@ -69,7 +69,7 @@ async let monitorResult = run(
69
69
.path("/usr/bin/tail"),
70
70
arguments: ["-f", "/path/to/nginx.log"]
71
71
) { execution, standardOutput in
72
-
fortryawait line in standardOutput.lines(encoding: UTF8.self) {
@@ -127,20 +128,20 @@ let result = try await run(.path("/bin/exe"), platformOptions: platformOptions)
127
128
### Flexible Input and Output Configurations
128
129
129
130
By default, `Subprocess`:
130
-
- Doesn’t send any input to the child process’s standard input
131
-
-Asks the user how to capture the output
132
-
- Ignores the child process’s standard error
131
+
- Doesn't send any input to the child process's standard input
132
+
-Requires you to specify how to capture the output
133
+
- Ignores the child process's standard error
133
134
134
135
You can tailor how `Subprocess` handles the standard input, standard output, and standard error by setting the `input`, `output`, and `error` parameters:
135
136
136
137
```swift
137
138
let content ="Hello Subprocess"
138
139
139
140
// Send "Hello Subprocess" to the standard input of `cat`
140
-
let result =tryawaitrun(.name("cat"), input: .string(content, using: UTF8.self))
141
+
let result =tryawaitrun(.name("cat"), input: .string(content), output: .string(limit: 4096))
141
142
142
143
// Collect both standard error and standard output as Data
143
-
let result =tryawaitrun(.name("cat"), output: .data, error: .data)
144
+
let result =tryawaitrun(.name("cat"), output: .data(limit: 4096), error: .data(limit: 4096))
144
145
```
145
146
146
147
`Subprocess` supports these input options:
@@ -155,13 +156,13 @@ Use it by setting `.none` for `input`.
155
156
156
157
This option reads input from a specified `FileDescriptor`. If `closeAfterSpawningProcess` is set to `true`, the subprocess will close the file descriptor after spawning. If `false`, you are responsible for closing it, even if the subprocess fails to spawn.
157
158
158
-
Use it by setting `.fileDescriptor(closeAfterSpawningProcess:)` for `input`.
159
+
Use it by setting `.fileDescriptor(_:closeAfterSpawningProcess:)` for `input`.
159
160
160
161
#### `StringInput`
161
162
162
163
This option reads input from a type conforming to `StringProtocol` using the specified encoding.
163
164
164
-
Use it by setting `.string(using:)` for `input`.
165
+
Use it by setting `.string(_:)` or `.string(_:using:)` for `input`.
165
166
166
167
#### `ArrayInput`
167
168
@@ -179,13 +180,13 @@ Use it by setting `.data` for `input`.
179
180
180
181
This option reads input from a sequence of `Data`.
181
182
182
-
Use it by setting `.sequence` for `input`.
183
+
Use it by setting `.sequence(_:)` for `input`.
183
184
184
185
#### `DataAsyncSequenceInput` (available with `SubprocessFoundation` trait)
185
186
186
187
This option reads input from an async sequence of `Data`.
187
188
188
-
Use it by setting `.asyncSequence` for `input`.
189
+
Use it by setting `.sequence(_:)` for `input`.
189
190
190
191
---
191
192
@@ -201,19 +202,25 @@ Use it by setting `.discarded` for `output` or `error`.
201
202
202
203
This option writes output to a specified `FileDescriptor`. You can choose to have the `Subprocess` close the file descriptor after spawning.
203
204
204
-
Use it by setting `.fileDescriptor(closeAfterSpawningProcess:)` for `output` or `error`.
205
+
Use it by setting `.fileDescriptor(_:closeAfterSpawningProcess:)` for `output` or `error`.
205
206
206
207
#### `StringOutput`
207
208
208
209
This option collects output as a `String` with the given encoding.
209
210
210
-
Use it by setting `.string(limit:encoding:)` for `output` or `error`.
211
+
Use it by setting `.string(limit:)` or `.string(limit:encoding:)` for `output` or `error`.
211
212
212
213
#### `BytesOutput`
213
214
214
215
This option collects output as `[UInt8]`.
215
216
216
-
Use it by setting`.bytes(limit:)` for `output` or `error`.
217
+
Use it by setting `.bytes(limit:)` for `output` or `error`.
218
+
219
+
#### `DataOutput` (available with `SubprocessFoundation` trait)
220
+
221
+
This option collects output as `Data`.
222
+
223
+
Use it by setting `.data(limit:)` for `output` or `error`.
0 commit comments