@@ -13,11 +13,11 @@ import XCTestDynamicOverlay
1313public struct FlagFormatter : Sendable {
1414 /// Formats a key string
1515 public let prefix : @Sendable ( ) -> String
16- public let body : @Sendable ( _ key: String ) -> String
16+ public let key : @Sendable ( _ key: String ) -> String
1717
1818 @Sendable
1919 public func format( key: String ) -> String {
20- prefix ( ) + body ( key)
20+ prefix ( ) + self . key ( key)
2121 }
2222
2323 @Sendable
@@ -29,73 +29,80 @@ public struct FlagFormatter: Sendable {
2929 ///
3030 /// - Parameters
3131 /// - prefix: Closure that returns the prefix string
32- /// - body : Closure that transforms the key string for formatting
32+ /// - key : Closure that transforms the key string for formatting
3333 public init (
3434 prefix: @escaping @Sendable ( ) -> String ,
35- body : @escaping @Sendable ( _ key: String ) -> String
35+ key : @escaping @Sendable ( _ key: String ) -> String
3636 ) {
3737 self . prefix = prefix
38- self . body = body
38+ self . key = key
3939 }
4040
4141 /// Initialize a new formatter
4242 ///
4343 /// - Parameters
4444 /// - prefix: Name spaced closure that returns the prefix string for a Flag
45- /// - body : Name spaced closure that transforms the key string for formatting
46- public init ( prefix: PrefixFormatter = . empty, body : BodyFormatter = . empty) {
45+ /// - key : Name spaced closure that transforms the key string for formatting
46+ public init ( prefix: PrefixFormatter = . empty, key : KeyFormatter = . empty) {
4747 self . init (
4848 prefix: prefix. transform,
49- body : body . transform
49+ key : key . transform
5050 )
5151 }
5252}
5353
5454/// Formats `Option`s to match how different executables format arguments
5555public struct OptionFormatter : Sendable {
5656 public let prefix : @Sendable ( ) -> String
57- public let body : @Sendable ( _ key: String ) -> String
58- public let separator : @Sendable ( ) -> String
57+ public let key : @Sendable ( _ key: String ) -> String
58+ public let separator : @Sendable ( _ key: String , _ value: String ) -> [ String ]
59+ public let value : @Sendable ( _ value: String ) -> String
5960
60- public func format( key: String , value: String ) -> String {
61- prefix ( ) + body ( key) + separator ( ) + value
61+ public func format( key: String , value: String ) -> [ String ] {
62+ separator ( prefix ( ) + self . key ( key) , self . value ( value) )
6263 }
6364
64- func format( encoding: OptionEncoding ) -> String {
65+ func format( encoding: OptionEncoding ) -> [ String ] {
6566 format ( key: encoding. key, value: encoding. value)
6667 }
6768
6869 /// Initialize a new formatter
6970 ///
7071 /// - Parameters
7172 /// - prefix: Closure that returns the prefix string
72- /// - body : Closure that transforms the key string for formatting
73+ /// - key : Closure that transforms the key string for formatting
7374 /// - separator: Closure that returns the string that separates the key and value
75+ /// - value: Closure that transforms the value string for formatting
7476 public init (
7577 prefix: @escaping @Sendable ( ) -> String ,
76- body: @escaping @Sendable ( _ key: String ) -> String ,
77- separator: @escaping @Sendable ( ) -> String
78+ key: @escaping @Sendable ( _ key: String ) -> String ,
79+ separator: @escaping @Sendable ( _ key: String , _ value: String ) -> [ String ] ,
80+ value: @escaping @Sendable ( _ value: String ) -> String
7881 ) {
7982 self . prefix = prefix
80- self . body = body
83+ self . key = key
8184 self . separator = separator
85+ self . value = value
8286 }
8387
8488 /// Initialize a new formatter
8589 ///
8690 /// - Parameters
8791 /// - prefix: Name spaced closure that returns the prefix string for a Flag
88- /// - body : Name spaced closure that transforms the key string for formatting
92+ /// - key : Name spaced closure that transforms the key string for formatting
8993 /// - separator: Name spaced closure that returns the string that separates the key and value
94+ /// - value: Name spaced closure that transforms the value string for formatting
9095 public init (
9196 prefix: PrefixFormatter = . empty,
92- body: BodyFormatter = . empty,
93- separator: SeparatorFormatter = . space
97+ key: KeyFormatter = . empty,
98+ separator: SeparatorFormatter = . separate,
99+ value: KeyFormatter = . empty
94100 ) {
95101 self . init (
96102 prefix: prefix. transform,
97- body: body. transform,
98- separator: separator. transform
103+ key: key. transform,
104+ separator: separator. transform,
105+ value: value. transform
99106 )
100107 }
101108}
@@ -116,7 +123,7 @@ public struct PrefixFormatter: Sendable {
116123}
117124
118125/// Name space for a closure that transforms a Flag or Option's key
119- public struct BodyFormatter : Sendable {
126+ public struct KeyFormatter : Sendable {
120127 public let transform : @Sendable ( _ key: String ) -> String
121128
122129 public init ( _ transform: @escaping @Sendable ( _ key: String ) -> String ) {
@@ -126,18 +133,20 @@ public struct BodyFormatter: Sendable {
126133 public static let empty = Self { $0 }
127134 public static let kebabCase = Self ( CaseConverter . kebabCase)
128135 public static let snakeCase = Self ( CaseConverter . snakeCase)
136+ public static let singleQuote = Self { " ' \( $0) ' " }
129137}
130138
131- /// Name space for a closure that returns the separator string between an Option's key and value
139+ /// Name space for a closure that returns the Option's key and value separated by a string or as separate elements in an
140+ /// array
132141public struct SeparatorFormatter : Sendable {
133- public let transform : @Sendable ( ) -> String
142+ public let transform : @Sendable ( _ key : String , _ value : String ) -> [ String ]
134143
135- public init ( _ transform: @escaping @Sendable ( ) -> String ) {
144+ public init ( _ transform: @escaping @Sendable ( _ key : String , _ value : String ) -> [ String ] ) {
136145 self . transform = transform
137146 }
138147
139- public static let space = Self { StaticString . space . description }
140- public static let equal = Self { StaticString . equal. description }
148+ public static let separate = Self { [ $0 , $1 ] }
149+ public static let equal = Self { [ " \( $0 ) \( StaticString . equal. description) \( $1 ) " ] }
141150}
142151
143152// MARK: Dependency
0 commit comments