@@ -13,11 +13,11 @@ import XCTestDynamicOverlay
13
13
public struct FlagFormatter : Sendable {
14
14
/// Formats a key string
15
15
public let prefix : @Sendable ( ) -> String
16
- public let body : @Sendable ( _ key: String ) -> String
16
+ public let key : @Sendable ( _ key: String ) -> String
17
17
18
18
@Sendable
19
19
public func format( key: String ) -> String {
20
- prefix ( ) + body ( key)
20
+ prefix ( ) + self . key ( key)
21
21
}
22
22
23
23
@Sendable
@@ -29,73 +29,80 @@ public struct FlagFormatter: Sendable {
29
29
///
30
30
/// - Parameters
31
31
/// - 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
33
33
public init (
34
34
prefix: @escaping @Sendable ( ) -> String ,
35
- body : @escaping @Sendable ( _ key: String ) -> String
35
+ key : @escaping @Sendable ( _ key: String ) -> String
36
36
) {
37
37
self . prefix = prefix
38
- self . body = body
38
+ self . key = key
39
39
}
40
40
41
41
/// Initialize a new formatter
42
42
///
43
43
/// - Parameters
44
44
/// - 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) {
47
47
self . init (
48
48
prefix: prefix. transform,
49
- body : body . transform
49
+ key : key . transform
50
50
)
51
51
}
52
52
}
53
53
54
54
/// Formats `Option`s to match how different executables format arguments
55
55
public struct OptionFormatter : Sendable {
56
56
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
59
60
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) )
62
63
}
63
64
64
- func format( encoding: OptionEncoding ) -> String {
65
+ func format( encoding: OptionEncoding ) -> [ String ] {
65
66
format ( key: encoding. key, value: encoding. value)
66
67
}
67
68
68
69
/// Initialize a new formatter
69
70
///
70
71
/// - Parameters
71
72
/// - 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
73
74
/// - separator: Closure that returns the string that separates the key and value
75
+ /// - value: Closure that transforms the value string for formatting
74
76
public init (
75
77
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
78
81
) {
79
82
self . prefix = prefix
80
- self . body = body
83
+ self . key = key
81
84
self . separator = separator
85
+ self . value = value
82
86
}
83
87
84
88
/// Initialize a new formatter
85
89
///
86
90
/// - Parameters
87
91
/// - 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
89
93
/// - 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
90
95
public init (
91
96
prefix: PrefixFormatter = . empty,
92
- body: BodyFormatter = . empty,
93
- separator: SeparatorFormatter = . space
97
+ key: KeyFormatter = . empty,
98
+ separator: SeparatorFormatter = . separate,
99
+ value: KeyFormatter = . empty
94
100
) {
95
101
self . init (
96
102
prefix: prefix. transform,
97
- body: body. transform,
98
- separator: separator. transform
103
+ key: key. transform,
104
+ separator: separator. transform,
105
+ value: value. transform
99
106
)
100
107
}
101
108
}
@@ -116,7 +123,7 @@ public struct PrefixFormatter: Sendable {
116
123
}
117
124
118
125
/// Name space for a closure that transforms a Flag or Option's key
119
- public struct BodyFormatter : Sendable {
126
+ public struct KeyFormatter : Sendable {
120
127
public let transform : @Sendable ( _ key: String ) -> String
121
128
122
129
public init ( _ transform: @escaping @Sendable ( _ key: String ) -> String ) {
@@ -126,18 +133,20 @@ public struct BodyFormatter: Sendable {
126
133
public static let empty = Self { $0 }
127
134
public static let kebabCase = Self ( CaseConverter . kebabCase)
128
135
public static let snakeCase = Self ( CaseConverter . snakeCase)
136
+ public static let singleQuote = Self { " ' \( $0) ' " }
129
137
}
130
138
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
132
141
public struct SeparatorFormatter : Sendable {
133
- public let transform : @Sendable ( ) -> String
142
+ public let transform : @Sendable ( _ key : String , _ value : String ) -> [ String ]
134
143
135
- public init ( _ transform: @escaping @Sendable ( ) -> String ) {
144
+ public init ( _ transform: @escaping @Sendable ( _ key : String , _ value : String ) -> [ String ] ) {
136
145
self . transform = transform
137
146
}
138
147
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 ) " ] }
141
150
}
142
151
143
152
// MARK: Dependency
0 commit comments