1717import Foundation
1818
1919/// Options for JSON rendering, wrapping the knobs on `JSONEncoder`.
20- struct JSONOptions {
21- var outputFormatting : JSONEncoder . OutputFormatting = [ ]
22- var dateEncodingStrategy : JSONEncoder . DateEncodingStrategy = . deferredToDate
20+ public struct JSONOptions : Sendable {
21+ public var outputFormatting : JSONEncoder . OutputFormatting = [ ]
22+ public var dateEncodingStrategy : JSONEncoder . DateEncodingStrategy = . deferredToDate
2323
24- static let compact = JSONOptions ( )
25- static let prettySorted = JSONOptions ( outputFormatting: [ . prettyPrinted, . sortedKeys] )
24+ public static let compact = JSONOptions ( )
25+ public static let prettySorted = JSONOptions ( outputFormatting: [ . prettyPrinted, . sortedKeys] )
26+
27+ public init (
28+ outputFormatting: JSONEncoder . OutputFormatting = [ ] ,
29+ dateEncodingStrategy: JSONEncoder . DateEncodingStrategy = . deferredToDate
30+ ) {
31+ self . outputFormatting = outputFormatting
32+ self . dateEncodingStrategy = dateEncodingStrategy
33+ }
2634}
2735
2836/// Renders an `Encodable` value as a JSON string.
29- func renderJSON< T: Encodable > ( _ value: T , options: JSONOptions = . compact) throws -> String {
37+ public func renderJSON< T: Encodable > ( _ value: T , options: JSONOptions = . compact) throws -> String {
3038 let encoder = JSONEncoder ( )
3139 encoder. outputFormatting = options. outputFormatting
3240 encoder. dateEncodingStrategy = options. dateEncodingStrategy
@@ -35,15 +43,15 @@ func renderJSON<T: Encodable>(_ value: T, options: JSONOptions = .compact) throw
3543}
3644
3745/// Renders a list of displayable items as a table (with header) or quiet-mode identifiers.
38- func renderList< T: ListDisplayable > ( _ items: [ T ] , quiet: Bool ) -> String {
46+ public func renderList< T: ListDisplayable > ( _ items: [ T ] , quiet: Bool ) -> String {
3947 if quiet {
4048 return items. map ( \. quietValue) . joined ( separator: " \n " )
4149 }
4250 return renderTable ( items)
4351}
4452
4553/// Renders a list of displayable items as a column-aligned table with a header row.
46- func renderTable< T: ListDisplayable > ( _ items: [ T ] ) -> String {
54+ public func renderTable< T: ListDisplayable > ( _ items: [ T ] ) -> String {
4755 var rows : [ [ String ] ] = [ T . tableHeader]
4856 for item in items {
4957 rows. append ( item. tableRow)
@@ -53,7 +61,7 @@ func renderTable<T: ListDisplayable>(_ items: [T]) -> String {
5361
5462/// Writes rendered output to stdout. No-ops on empty strings to avoid blank lines
5563/// (e.g., `container list -q` with zero results should produce no output, not a newline).
56- func emit( _ output: String ) {
64+ public func emit( _ output: String ) {
5765 if !output. isEmpty {
5866 print ( output)
5967 }
0 commit comments