@@ -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,58 +29,58 @@ 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 ]
5959 public let value : @Sendable ( _ value: String ) -> String
6060
61- public func format( key: String , value: String ) -> String {
62- prefix ( ) + body ( key) + separator ( ) + self . value ( value)
61+ public func format( key: String , value: String ) -> [ String ] {
62+ separator ( prefix ( ) + self . key ( key) , self . value ( value) )
6363 }
6464
65- func format( encoding: OptionEncoding ) -> String {
65+ func format( encoding: OptionEncoding ) -> [ String ] {
6666 format ( key: encoding. key, value: encoding. value)
6767 }
6868
6969 /// Initialize a new formatter
7070 ///
7171 /// - Parameters
7272 /// - prefix: Closure that returns the prefix string
73- /// - body : Closure that transforms the key string for formatting
73+ /// - key : Closure that transforms the key string for formatting
7474 /// - separator: Closure that returns the string that separates the key and value
7575 /// - value: Closure that transforms the value string for formatting
7676 public init (
7777 prefix: @escaping @Sendable ( ) -> String ,
78- body : @escaping @Sendable ( _ key: String ) -> String ,
79- separator: @escaping @Sendable ( ) -> String ,
78+ key : @escaping @Sendable ( _ key: String ) -> String ,
79+ separator: @escaping @Sendable ( _ key : String , _ value : String ) -> [ String ] ,
8080 value: @escaping @Sendable ( _ value: String ) -> String
8181 ) {
8282 self . prefix = prefix
83- self . body = body
83+ self . key = key
8484 self . separator = separator
8585 self . value = value
8686 }
@@ -89,18 +89,18 @@ public struct OptionFormatter: Sendable {
8989 ///
9090 /// - Parameters
9191 /// - prefix: Name spaced closure that returns the prefix string for a Flag
92- /// - body : Name spaced closure that transforms the key string for formatting
92+ /// - key : Name spaced closure that transforms the key string for formatting
9393 /// - separator: Name spaced closure that returns the string that separates the key and value
9494 /// - value: Name spaced closure that transforms the value string for formatting
9595 public init (
9696 prefix: PrefixFormatter = . empty,
97- body : BodyFormatter = . empty,
98- separator: SeparatorFormatter = . space ,
99- value: BodyFormatter = . empty
97+ key : KeyFormatter = . empty,
98+ separator: SeparatorFormatter = . separate ,
99+ value: KeyFormatter = . empty
100100 ) {
101101 self . init (
102102 prefix: prefix. transform,
103- body : body . transform,
103+ key : key . transform,
104104 separator: separator. transform,
105105 value: value. transform
106106 )
@@ -123,7 +123,7 @@ public struct PrefixFormatter: Sendable {
123123}
124124
125125/// Name space for a closure that transforms a Flag or Option's key
126- public struct BodyFormatter : Sendable {
126+ public struct KeyFormatter : Sendable {
127127 public let transform : @Sendable ( _ key: String ) -> String
128128
129129 public init ( _ transform: @escaping @Sendable ( _ key: String ) -> String ) {
@@ -136,16 +136,16 @@ public struct BodyFormatter: Sendable {
136136 public static let singleQuote = Self { " ' \( $0) ' " }
137137}
138138
139- /// 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 array
140140public struct SeparatorFormatter : Sendable {
141- public let transform : @Sendable ( ) -> String
141+ public let transform : @Sendable ( _ key : String , _ value : String ) -> [ String ]
142142
143- public init ( _ transform: @escaping @Sendable ( ) -> String ) {
143+ public init ( _ transform: @escaping @Sendable ( _ key : String , _ value : String ) -> [ String ] ) {
144144 self . transform = transform
145145 }
146146
147- public static let space = Self { StaticString . space . description }
148- public static let equal = Self { StaticString . equal. description }
147+ public static let separate = Self { [ $0 , $1 ] }
148+ public static let equal = Self { [ " \( $0 ) \( StaticString . equal. description) \( $1 ) " ] }
149149}
150150
151151// MARK: Dependency
0 commit comments