Skip to content

Commit 69920c1

Browse files
committed
Fix documentation throughout the codebase and enforce that all public symbols have documentation.
1 parent f0ba4f4 commit 69920c1

20 files changed

+289
-182
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

.swift-format

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"prioritizeKeepingFunctionOutputTogether": false,
2424
"respectsExistingLineBreaks": true,
2525
"rules": {
26-
"AllPublicDeclarationsHaveDocumentation": false,
26+
"AllPublicDeclarationsHaveDocumentation": true,
2727
"AlwaysUseLiteralForEmptyCollectionInit": false,
2828
"AlwaysUseLowerCamelCase": false,
2929
"AmbiguousTrailingClosureOverload": false,

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 returns a
21+
/// `CollectedResult` containing 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 returns a
63+
/// `CollectedResult` containing 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,
@@ -138,21 +136,19 @@ public func run<
138136
// MARK: - Custom Execution Body
139137

140138
/// Run an executable with given parameters and a custom closure
141-
/// to manage the running subprocess' lifetime and stream its standard output.
139+
/// to manage the running subprocess lifetime.
142140
/// - Parameters:
143141
/// - executable: The executable to run.
144142
/// - arguments: The arguments to pass to the executable.
145143
/// - environment: The environment in which to run the executable.
146144
/// - workingDirectory: The working directory in which to run the executable.
147-
/// - platformOptions: The platform specific options to use
148-
/// when running the executable.
145+
/// - platformOptions: The platform-specific options to use when running the executable.
149146
/// - input: The input to send to the executable.
150-
/// - output: How to manager executable standard output.
151-
/// - error: How to manager executable standard error.
147+
/// - output: How to manage executable standard output.
148+
/// - error: How to manage executable standard error.
152149
/// - isolation: the isolation context to run the body closure.
153150
/// - body: The custom execution body to manually control the running process
154-
/// - Returns an executableResult type containing the return value
155-
/// of the closure.
151+
/// - Returns: an `ExecutableResult` type containing the return value of the closure.
156152
public func run<Result, Input: InputProtocol, Output: OutputProtocol, Error: OutputProtocol>(
157153
_ executable: Executable,
158154
arguments: Arguments = [],
@@ -198,21 +194,19 @@ public func run<Result, Input: InputProtocol, Output: OutputProtocol, Error: Out
198194
}
199195
}
200196

201-
/// Run an executable with given parameters and a custom closure
202-
/// to manage the running subprocess' lifetime and stream its standard output.
197+
/// Run an executable with given parameters and a custom closure to manage the
198+
/// running subprocess' lifetime and stream its standard output.
203199
/// - Parameters:
204200
/// - executable: The executable to run.
205201
/// - arguments: The arguments to pass to the executable.
206202
/// - environment: The environment in which to run the executable.
207203
/// - workingDirectory: The working directory in which to run the executable.
208-
/// - platformOptions: The platform specific options to use
209-
/// when running the executable.
204+
/// - platformOptions: The platform-specific options to use when running the executable.
210205
/// - input: The input to send to the executable.
211-
/// - error: How to manager executable standard error.
206+
/// - error: How to manage executable standard error.
212207
/// - isolation: the isolation context to run the body closure.
213-
/// - body: The custom execution body to manually control the running process
214-
/// - Returns an executableResult type containing the return value
215-
/// of the closure.
208+
/// - body: The custom execution body to manually control the running process.
209+
/// - Returns: an `ExecutableResult` type containing the return value of the closure.
216210
public func run<Result, Input: InputProtocol, Error: OutputProtocol>(
217211
_ executable: Executable,
218212
arguments: Arguments = [],
@@ -260,21 +254,19 @@ public func run<Result, Input: InputProtocol, Error: OutputProtocol>(
260254
}
261255
}
262256

263-
/// Run an executable with given parameters and a custom closure
264-
/// to manage the running subprocess' lifetime and stream its standard error.
257+
/// Run an executable with given parameters and a custom closure to manage the
258+
/// running subprocess' lifetime and stream its standard error.
265259
/// - Parameters:
266260
/// - executable: The executable to run.
267261
/// - arguments: The arguments to pass to the executable.
268262
/// - environment: The environment in which to run the executable.
269263
/// - workingDirectory: The working directory in which to run the executable.
270-
/// - platformOptions: The platform specific options to use
271-
/// when running the executable.
264+
/// - platformOptions: The platform-specific options to use when running the executable.
272265
/// - input: The input to send to the executable.
273-
/// - output: How to manager executable standard output.
274-
/// - isolation: the isolation context to run the body closure.
266+
/// - output: How to manage executable standard output.
267+
/// - isolation: The isolation context to run the body closure.
275268
/// - body: The custom execution body to manually control the running process
276-
/// - Returns an executableResult type containing the return value
277-
/// of the closure.
269+
/// - Returns: an `ExecutableResult` type containing the return value of the closure.
278270
public func run<Result, Input: InputProtocol, Output: OutputProtocol>(
279271
_ executable: Executable,
280272
arguments: Arguments = [],
@@ -322,21 +314,18 @@ public func run<Result, Input: InputProtocol, Output: OutputProtocol>(
322314
}
323315
}
324316

325-
/// Run an executable with given parameters and a custom closure
326-
/// to manage the running subprocess' lifetime, write to its
327-
/// standard input, and stream its standard output.
317+
/// Run an executable with given parameters and a custom closure to manage the
318+
/// running subprocess' lifetime, write to its standard input, and stream its standard output.
328319
/// - Parameters:
329320
/// - executable: The executable to run.
330321
/// - arguments: The arguments to pass to the executable.
331322
/// - environment: The environment in which to run the executable.
332323
/// - workingDirectory: The working directory in which to run the executable.
333-
/// - platformOptions: The platform specific options to use
334-
/// when running the executable.
335-
/// - error: How to manager executable standard error.
324+
/// - platformOptions: The platform-specific options to use when running the executable.
325+
/// - error: How to manage executable standard error.
336326
/// - isolation: the isolation context to run the body closure.
337327
/// - body: The custom execution body to manually control the running process
338-
/// - Returns an executableResult type containing the return value
339-
/// of the closure.
328+
/// - Returns: An `ExecutableResult` type containing the return value of the closure.
340329
public func run<Result, Error: OutputProtocol>(
341330
_ executable: Executable,
342331
arguments: Arguments = [],
@@ -367,21 +356,18 @@ public func run<Result, Error: OutputProtocol>(
367356
}
368357
}
369358

370-
/// Run an executable with given parameters and a custom closure
371-
/// to manage the running subprocess' lifetime, write to its
372-
/// standard input, and stream its standard error.
359+
/// Run an executable with given parameters and a custom closure to manage the
360+
/// running subprocess' lifetime, write to its standard input, and stream its standard error.
373361
/// - Parameters:
374362
/// - executable: The executable to run.
375363
/// - arguments: The arguments to pass to the executable.
376364
/// - environment: The environment in which to run the executable.
377365
/// - workingDirectory: The working directory in which to run the executable.
378-
/// - platformOptions: The platform specific options to use
379-
/// when running the executable.
380-
/// - output: How to manager executable standard output.
366+
/// - platformOptions: The platform-specific options to use when running the executable.
367+
/// - output: How to manage executable standard output.
381368
/// - isolation: the isolation context to run the body closure.
382369
/// - body: The custom execution body to manually control the running process
383-
/// - Returns an executableResult type containing the return value
384-
/// of the closure.
370+
/// - Returns: An `ExecutableResult` type containing the return value of the closure.
385371
public func run<Result, Output: OutputProtocol>(
386372
_ executable: Executable,
387373
arguments: Arguments = [],
@@ -413,19 +399,17 @@ public func run<Result, Output: OutputProtocol>(
413399
}
414400

415401
/// Run an executable with given parameters and a custom closure
416-
/// to manage the running subprocess' lifetime, write to its
402+
/// to manage the running subprocess lifetime, write to its
417403
/// standard input, and stream its standard output and standard error.
418404
/// - Parameters:
419405
/// - executable: The executable to run.
420406
/// - arguments: The arguments to pass to the executable.
421407
/// - environment: The environment in which to run the executable.
422408
/// - workingDirectory: The working directory in which to run the executable.
423-
/// - platformOptions: The platform specific options to use
424-
/// when running the executable.
409+
/// - platformOptions: The platform-specific options to use when running the executable.
425410
/// - isolation: the isolation context to run the body closure.
426411
/// - body: The custom execution body to manually control the running process
427-
/// - Returns an executableResult type containing the return value
428-
/// of the closure.
412+
/// - Returns: an `ExecutableResult` type containing the return value of the closure.
429413
public func run<Result>(
430414
_ executable: Executable,
431415
arguments: Arguments = [],
@@ -474,7 +458,7 @@ public func run<Result>(
474458
/// - input: The input to send to the executable.
475459
/// - output: The method to use for redirecting the standard output.
476460
/// - error: The method to use for redirecting the standard error.
477-
/// - Returns a CollectedResult containing the result of the run.
461+
/// - Returns: a `CollectedResult` containing the result of the run.
478462
public func run<
479463
Input: InputProtocol,
480464
Output: OutputProtocol,
@@ -562,9 +546,8 @@ public func run<
562546
/// - isolation: the isolation context to run the body closure.
563547
/// - body: The custom configuration body to manually control
564548
/// the running process, write to its standard input, stream
565-
/// its standard output and standard error.
566-
/// - Returns an executableResult type containing the return value
567-
/// of the closure.
549+
/// the standard output and standard error.
550+
/// - Returns: an `ExecutableResult` type containing the return value of the closure.
568551
public func run<Result>(
569552
_ configuration: Configuration,
570553
isolation: isolated (any Actor)? = #isolation,

0 commit comments

Comments
 (0)