Skip to content

Commit ae75fdf

Browse files
iCharlesHuheckj
andauthored
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]>
1 parent 847c015 commit ae75fdf

19 files changed

+304
-185
lines changed

.spi.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
version: 1
2+
metadata:
3+
authors: Apple Inc.
24
builder:
35
configs:
4-
- documentation_targets: [Subprocess]
6+
- swift_version: 6.1
7+
documentation_targets: [Subprocess]
8+
scheme: Subprocess

README.md

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ dependencies: [
1515
.package(url: "https://github.com/swiftlang/swift-subprocess.git", branch: "main")
1616
]
1717
```
18-
Then, adding the `Subprocess` module to your target dependencies:
18+
Then, add the `Subprocess` module to your target dependencies:
1919

2020
```swift
2121
.target(
@@ -29,27 +29,27 @@ Then, adding the `Subprocess` module to your target dependencies:
2929
`Subprocess` offers two [package traits](https://github.com/swiftlang/swift-evolution/blob/main/proposals/0450-swiftpm-package-traits.md):
3030

3131
- `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.
3333

3434
Please find the API proposal [here](https://github.com/swiftlang/swift-foundation/blob/main/Proposals/0007-swift-subprocess.md).
3535

3636
### Swift Versions
3737

38-
The minimal supported Swift version is **Swift 6.1**.
38+
The minimum supported Swift version is **Swift 6.1**.
3939

4040
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).
4141

4242

4343
## Feature Overview
4444

45-
### Run and Asynchonously Collect Output
45+
### Run and Asynchronously Collect Output
4646

4747
The easiest way to spawn a process with `Subprocess` is to simply run it and await its `CollectedResult`:
4848

4949
```swift
5050
import Subprocess
5151

52-
let result = try await run(.name("ls"))
52+
let result = try await run(.name("ls"), output: .string(limit: 4096))
5353

5454
print(result.processIdentifier) // prints 1234
5555
print(result.terminationStatus) // prints exited(0)
@@ -69,7 +69,7 @@ async let monitorResult = run(
6969
.path("/usr/bin/tail"),
7070
arguments: ["-f", "/path/to/nginx.log"]
7171
) { execution, standardOutput in
72-
for try await line in standardOutput.lines(encoding: UTF8.self) {
72+
for try await line in standardOutput.lines() {
7373
// Parse the log text
7474
if line.contains("500") {
7575
// Oh no, 500 error
@@ -92,6 +92,7 @@ let result = try await run(
9292
// add `NewKey=NewValue`
9393
environment: .inherit.updating(["NewKey": "NewValue"]),
9494
workingDirectory: "/Users/",
95+
output: .string(limit: 4096)
9596
)
9697
```
9798

@@ -127,20 +128,20 @@ let result = try await run(.path("/bin/exe"), platformOptions: platformOptions)
127128
### Flexible Input and Output Configurations
128129

129130
By default, `Subprocess`:
130-
- Doesnt send any input to the child processs standard input
131-
- Asks the user how to capture the output
132-
- Ignores the child processs 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
133134

134135
You can tailor how `Subprocess` handles the standard input, standard output, and standard error by setting the `input`, `output`, and `error` parameters:
135136

136137
```swift
137138
let content = "Hello Subprocess"
138139

139140
// Send "Hello Subprocess" to the standard input of `cat`
140-
let result = try await run(.name("cat"), input: .string(content, using: UTF8.self))
141+
let result = try await run(.name("cat"), input: .string(content), output: .string(limit: 4096))
141142

142143
// Collect both standard error and standard output as Data
143-
let result = try await run(.name("cat"), output: .data, error: .data)
144+
let result = try await run(.name("cat"), output: .data(limit: 4096), error: .data(limit: 4096))
144145
```
145146

146147
`Subprocess` supports these input options:
@@ -155,13 +156,13 @@ Use it by setting `.none` for `input`.
155156

156157
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.
157158

158-
Use it by setting `.fileDescriptor(closeAfterSpawningProcess:)` for `input`.
159+
Use it by setting `.fileDescriptor(_:closeAfterSpawningProcess:)` for `input`.
159160

160161
#### `StringInput`
161162

162163
This option reads input from a type conforming to `StringProtocol` using the specified encoding.
163164

164-
Use it by setting `.string(using:)` for `input`.
165+
Use it by setting `.string(_:)` or `.string(_:using:)` for `input`.
165166

166167
#### `ArrayInput`
167168

@@ -179,13 +180,13 @@ Use it by setting `.data` for `input`.
179180

180181
This option reads input from a sequence of `Data`.
181182

182-
Use it by setting `.sequence` for `input`.
183+
Use it by setting `.sequence(_:)` for `input`.
183184

184185
#### `DataAsyncSequenceInput` (available with `SubprocessFoundation` trait)
185186

186187
This option reads input from an async sequence of `Data`.
187188

188-
Use it by setting `.asyncSequence` for `input`.
189+
Use it by setting `.sequence(_:)` for `input`.
189190

190191
---
191192

@@ -201,19 +202,25 @@ Use it by setting `.discarded` for `output` or `error`.
201202

202203
This option writes output to a specified `FileDescriptor`. You can choose to have the `Subprocess` close the file descriptor after spawning.
203204

204-
Use it by setting `.fileDescriptor(closeAfterSpawningProcess:)` for `output` or `error`.
205+
Use it by setting `.fileDescriptor(_:closeAfterSpawningProcess:)` for `output` or `error`.
205206

206207
#### `StringOutput`
207208

208209
This option collects output as a `String` with the given encoding.
209210

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`.
211212

212213
#### `BytesOutput`
213214

214215
This option collects output as `[UInt8]`.
215216

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`.
217224

218225

219226
### Cross-platform support

Sources/Subprocess/API.swift

Lines changed: 42 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,18 @@
1717

1818
// MARK: - Collected Result
1919

20-
/// Run an executable with given parameters asynchronously and returns
21-
/// a `CollectedResult` containing the output of the child process.
20+
/// Run an executable with given parameters asynchronously and return a
21+
/// collected result that contains the output of the child process.
2222
/// - Parameters:
2323
/// - executable: The executable to run.
2424
/// - arguments: The arguments to pass to the executable.
2525
/// - environment: The environment in which to run the executable.
2626
/// - workingDirectory: The working directory in which to run the executable.
27-
/// - platformOptions: The platform specific options to use
28-
/// when running the executable.
27+
/// - platformOptions: The platform-specific options to use when running the executable.
2928
/// - input: The input to send to the executable.
3029
/// - output: The method to use for redirecting the standard output.
3130
/// - error: The method to use for redirecting the standard error.
32-
/// - Returns a CollectedResult containing the result of the run.
31+
/// - Returns: a `CollectedResult` containing the result of the run.
3332
public func run<
3433
Input: InputProtocol,
3534
Output: OutputProtocol,
@@ -59,20 +58,19 @@ public func run<
5958
)
6059
}
6160

62-
/// Run an executable with given parameters asynchronously and returns
63-
/// a `CollectedResult` containing the output of the child process.
61+
#if SubprocessSpan
62+
/// Run an executable with given parameters asynchronously and return a
63+
/// collected result that contains the output of the child process.
6464
/// - Parameters:
6565
/// - executable: The executable to run.
6666
/// - arguments: The arguments to pass to the executable.
6767
/// - environment: The environment in which to run the executable.
6868
/// - workingDirectory: The working directory in which to run the executable.
69-
/// - platformOptions: The platform specific options to use
70-
/// when running the executable.
69+
/// - platformOptions: The platform-specific options to use when running the executable.
7170
/// - input: span to write to subprocess' standard input.
7271
/// - output: The method to use for redirecting the standard output.
7372
/// - error: The method to use for redirecting the standard error.
74-
/// - Returns a CollectedResult containing the result of the run.
75-
#if SubprocessSpan
73+
/// - Returns: a CollectedResult containing the result of the run.
7674
public func run<
7775
InputElement: BitwiseCopyable,
7876
Output: OutputProtocol,
@@ -106,21 +104,19 @@ public func run<
106104
// MARK: - Custom Execution Body
107105

108106
/// Run an executable with given parameters and a custom closure
109-
/// to manage the running subprocess' lifetime and stream its standard output.
107+
/// to manage the running subprocess lifetime.
110108
/// - Parameters:
111109
/// - executable: The executable to run.
112110
/// - arguments: The arguments to pass to the executable.
113111
/// - environment: The environment in which to run the executable.
114112
/// - workingDirectory: The working directory in which to run the executable.
115-
/// - platformOptions: The platform specific options to use
116-
/// when running the executable.
113+
/// - platformOptions: The platform-specific options to use when running the executable.
117114
/// - input: The input to send to the executable.
118-
/// - output: How to manager executable standard output.
119-
/// - error: How to manager executable standard error.
115+
/// - output: How to manage executable standard output.
116+
/// - error: How to manage executable standard error.
120117
/// - isolation: the isolation context to run the body closure.
121118
/// - body: The custom execution body to manually control the running process
122-
/// - Returns an executableResult type containing the return value
123-
/// of the closure.
119+
/// - Returns: an `ExecutableResult` type containing the return value of the closure.
124120
public func run<Result, Input: InputProtocol, Output: OutputProtocol, Error: OutputProtocol>(
125121
_ executable: Executable,
126122
arguments: Arguments = [],
@@ -150,21 +146,19 @@ public func run<Result, Input: InputProtocol, Output: OutputProtocol, Error: Out
150146
)
151147
}
152148

153-
/// Run an executable with given parameters and a custom closure
154-
/// to manage the running subprocess' lifetime and stream its standard output.
149+
/// Run an executable with given parameters and a custom closure to manage the
150+
/// running subprocess' lifetime and stream its standard output.
155151
/// - Parameters:
156152
/// - executable: The executable to run.
157153
/// - arguments: The arguments to pass to the executable.
158154
/// - environment: The environment in which to run the executable.
159155
/// - workingDirectory: The working directory in which to run the executable.
160-
/// - platformOptions: The platform specific options to use
161-
/// when running the executable.
156+
/// - platformOptions: The platform-specific options to use when running the executable.
162157
/// - input: The input to send to the executable.
163-
/// - error: How to manager executable standard error.
158+
/// - error: How to manage executable standard error.
164159
/// - isolation: the isolation context to run the body closure.
165-
/// - body: The custom execution body to manually control the running process
166-
/// - Returns an executableResult type containing the return value
167-
/// of the closure.
160+
/// - body: The custom execution body to manually control the running process.
161+
/// - Returns: an `ExecutableResult` type containing the return value of the closure.
168162
public func run<Result, Input: InputProtocol, Error: OutputProtocol>(
169163
_ executable: Executable,
170164
arguments: Arguments = [],
@@ -192,21 +186,19 @@ public func run<Result, Input: InputProtocol, Error: OutputProtocol>(
192186
)
193187
}
194188

195-
/// Run an executable with given parameters and a custom closure
196-
/// to manage the running subprocess' lifetime and stream its standard error.
189+
/// Run an executable with given parameters and a custom closure to manage the
190+
/// running subprocess' lifetime and stream its standard error.
197191
/// - Parameters:
198192
/// - executable: The executable to run.
199193
/// - arguments: The arguments to pass to the executable.
200194
/// - environment: The environment in which to run the executable.
201195
/// - workingDirectory: The working directory in which to run the executable.
202-
/// - platformOptions: The platform specific options to use
203-
/// when running the executable.
196+
/// - platformOptions: The platform-specific options to use when running the executable.
204197
/// - input: The input to send to the executable.
205-
/// - output: How to manager executable standard output.
206-
/// - isolation: the isolation context to run the body closure.
198+
/// - output: How to manage executable standard output.
199+
/// - isolation: The isolation context to run the body closure.
207200
/// - body: The custom execution body to manually control the running process
208-
/// - Returns an executableResult type containing the return value
209-
/// of the closure.
201+
/// - Returns: an `ExecutableResult` type containing the return value of the closure.
210202
public func run<Result, Input: InputProtocol, Output: OutputProtocol>(
211203
_ executable: Executable,
212204
arguments: Arguments = [],
@@ -234,21 +226,18 @@ public func run<Result, Input: InputProtocol, Output: OutputProtocol>(
234226
)
235227
}
236228

237-
/// Run an executable with given parameters and a custom closure
238-
/// to manage the running subprocess' lifetime, write to its
239-
/// standard input, and stream its standard output.
229+
/// Run an executable with given parameters and a custom closure to manage the
230+
/// running subprocess' lifetime, write to its standard input, and stream its standard output.
240231
/// - Parameters:
241232
/// - executable: The executable to run.
242233
/// - arguments: The arguments to pass to the executable.
243234
/// - environment: The environment in which to run the executable.
244235
/// - workingDirectory: The working directory in which to run the executable.
245-
/// - platformOptions: The platform specific options to use
246-
/// when running the executable.
247-
/// - error: How to manager executable standard error.
236+
/// - platformOptions: The platform-specific options to use when running the executable.
237+
/// - error: How to manage executable standard error.
248238
/// - isolation: the isolation context to run the body closure.
249239
/// - body: The custom execution body to manually control the running process
250-
/// - Returns an executableResult type containing the return value
251-
/// of the closure.
240+
/// - Returns: An `ExecutableResult` type containing the return value of the closure.
252241
public func run<Result, Error: OutputProtocol>(
253242
_ executable: Executable,
254243
arguments: Arguments = [],
@@ -274,21 +263,18 @@ public func run<Result, Error: OutputProtocol>(
274263
)
275264
}
276265

277-
/// Run an executable with given parameters and a custom closure
278-
/// to manage the running subprocess' lifetime, write to its
279-
/// standard input, and stream its standard error.
266+
/// Run an executable with given parameters and a custom closure to manage the
267+
/// running subprocess' lifetime, write to its standard input, and stream its standard error.
280268
/// - Parameters:
281269
/// - executable: The executable to run.
282270
/// - arguments: The arguments to pass to the executable.
283271
/// - environment: The environment in which to run the executable.
284272
/// - workingDirectory: The working directory in which to run the executable.
285-
/// - platformOptions: The platform specific options to use
286-
/// when running the executable.
287-
/// - output: How to manager executable standard output.
273+
/// - platformOptions: The platform-specific options to use when running the executable.
274+
/// - output: How to manage executable standard output.
288275
/// - isolation: the isolation context to run the body closure.
289276
/// - body: The custom execution body to manually control the running process
290-
/// - Returns an executableResult type containing the return value
291-
/// of the closure.
277+
/// - Returns: An `ExecutableResult` type containing the return value of the closure.
292278
public func run<Result, Output: OutputProtocol>(
293279
_ executable: Executable,
294280
arguments: Arguments = [],
@@ -315,19 +301,17 @@ public func run<Result, Output: OutputProtocol>(
315301
}
316302

317303
/// Run an executable with given parameters and a custom closure
318-
/// to manage the running subprocess' lifetime, write to its
304+
/// to manage the running subprocess lifetime, write to its
319305
/// standard input, and stream its standard output and standard error.
320306
/// - Parameters:
321307
/// - executable: The executable to run.
322308
/// - arguments: The arguments to pass to the executable.
323309
/// - environment: The environment in which to run the executable.
324310
/// - workingDirectory: The working directory in which to run the executable.
325-
/// - platformOptions: The platform specific options to use
326-
/// when running the executable.
311+
/// - platformOptions: The platform-specific options to use when running the executable.
327312
/// - isolation: the isolation context to run the body closure.
328313
/// - body: The custom execution body to manually control the running process
329-
/// - Returns an executableResult type containing the return value
330-
/// of the closure.
314+
/// - Returns: an `ExecutableResult` type containing the return value of the closure.
331315
public func run<Result>(
332316
_ executable: Executable,
333317
arguments: Arguments = [],
@@ -428,7 +412,7 @@ public func run<
428412
/// - input: The input to send to the executable.
429413
/// - output: The method to use for redirecting the standard output.
430414
/// - error: The method to use for redirecting the standard error.
431-
/// - Returns a CollectedResult containing the result of the run.
415+
/// - Returns: a `CollectedResult` containing the result of the run.
432416
public func run<
433417
Input: InputProtocol,
434418
Output: OutputProtocol,
@@ -714,9 +698,8 @@ public func run<Result, Output: OutputProtocol>(
714698
/// - isolation: the isolation context to run the body closure.
715699
/// - body: The custom configuration body to manually control
716700
/// the running process, write to its standard input, stream
717-
/// its standard output and standard error.
718-
/// - Returns an executableResult type containing the return value
719-
/// of the closure.
701+
/// the standard output and standard error.
702+
/// - Returns: an `ExecutableResult` type containing the return value of the closure.
720703
public func run<Result>(
721704
_ configuration: Configuration,
722705
isolation: isolated (any Actor)? = #isolation,

0 commit comments

Comments
 (0)