Skip to content

Commit c99e84e

Browse files
Avoid leaking implementation in PlatformOptions description (#284)
`PlatformOptions.description(withIndent:)` renders `ConsoleBehavior` and `WindowStyle` with `String(describing:)`, which exposes the private `storage` wrapper (for example, `ConsoleBehavior(storage: inherit)`) instead of just `inherit`, leaking an implementation detail that isn't part of the public API. Give both types `CustomStringConvertible` conformance and interpolate them directly.
1 parent f072a47 commit c99e84e

1 file changed

Lines changed: 46 additions & 2 deletions

File tree

Sources/Subprocess/Platforms/Subprocess+Windows.swift

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -453,14 +453,58 @@ public struct PlatformOptions: Sendable {
453453
public init() {}
454454
}
455455

456+
extension PlatformOptions.ConsoleBehavior: CustomStringConvertible, CustomDebugStringConvertible {
457+
/// A textual representation of how the console appears when spawning a
458+
/// new process.
459+
public var description: String {
460+
switch self.storage {
461+
case .createNew:
462+
return "createNew"
463+
case .detach:
464+
return "detach"
465+
case .inherit:
466+
return "inherit"
467+
}
468+
}
469+
470+
/// A debug-oriented textual representation of how the console appears when
471+
/// spawning a new process.
472+
public var debugDescription: String {
473+
return self.description
474+
}
475+
}
476+
477+
extension PlatformOptions.WindowStyle: CustomStringConvertible, CustomDebugStringConvertible {
478+
/// A textual representation of how the window appears when spawning a
479+
/// new process.
480+
public var description: String {
481+
switch self.storage {
482+
case .normal:
483+
return "normal"
484+
case .hidden:
485+
return "hidden"
486+
case .maximized:
487+
return "maximized"
488+
case .minimized:
489+
return "minimized"
490+
}
491+
}
492+
493+
/// A debug-oriented textual representation of how the window appears when
494+
/// spawning a new process.
495+
public var debugDescription: String {
496+
return self.description
497+
}
498+
}
499+
456500
extension PlatformOptions: CustomStringConvertible, CustomDebugStringConvertible {
457501
internal func description(withIndent indent: Int) -> String {
458502
let indent = String(repeating: " ", count: indent * 4)
459503
return """
460504
PlatformOptions(
461505
\(indent) userCredentials: \(String(describing: self.userCredentials)),
462-
\(indent) consoleBehavior: \(String(describing: self.consoleBehavior)),
463-
\(indent) windowStyle: \(String(describing: self.windowStyle)),
506+
\(indent) consoleBehavior: \(self.consoleBehavior),
507+
\(indent) windowStyle: \(self.windowStyle),
464508
\(indent) createProcessGroup: \(self.createProcessGroup),
465509
\(indent) preSpawnProcessConfigurator: \(self.preSpawnProcessConfigurator == nil ? "not set" : "set")
466510
\(indent))

0 commit comments

Comments
 (0)