File tree Expand file tree Collapse file tree 3 files changed +21
-28
lines changed
Tests/ArgumentParserUnitTests Expand file tree Collapse file tree 3 files changed +21
-28
lines changed Original file line number Diff line number Diff line change @@ -208,6 +208,25 @@ extension ParsableArguments {
208
208
}
209
209
}
210
210
211
+ /// Unboxes the given value if it is a `nil` value.
212
+ ///
213
+ /// If the value passed is the `.none` case of any optional type, this function
214
+ /// returns `nil`.
215
+ ///
216
+ /// let intAsAny = (1 as Int?) as Any
217
+ /// let nilAsAny = (nil as Int?) as Any
218
+ /// nilOrValue(intAsAny) // Optional(1) as Any?
219
+ /// nilOrValue(nilAsAny) // nil as Any?
220
+ func nilOrValue( _ value: Any ) -> Any ? {
221
+ if case Optional < Any > . none = value {
222
+ return nil
223
+ } else {
224
+ return value
225
+ }
226
+ }
227
+
228
+ /// Existential protocol for property wrappers, so that they can provide
229
+ /// the argument set that they define.
211
230
protocol ArgumentSetProvider {
212
231
func argumentSet( for key: InputKey ) -> ArgumentSet
213
232
}
@@ -241,7 +260,7 @@ extension ArgumentSet {
241
260
key: InputKey ( rawValue: codingKey) ,
242
261
kind: . default,
243
262
parser: { _ in nil } ,
244
- default: Mirror . realValue ( for : child) ,
263
+ default: nilOrValue ( child. value ) ,
245
264
completion: . default)
246
265
definition. help. help = . hidden
247
266
return ArgumentSet ( definition)
Load Diff This file was deleted.
Original file line number Diff line number Diff line change @@ -29,7 +29,7 @@ extension MirrorTests {
29
29
}
30
30
XCTAssertEqual ( stringValue, expectedString)
31
31
} else {
32
- XCTAssertNil ( Mirror . realValue ( for : child) )
32
+ XCTAssertNil ( nilOrValue ( child. value ) )
33
33
// This is why we use `unwrapedOptionalValue` for optionality checks
34
34
// Even though the `value` is `nil` this returns `false`
35
35
XCTAssertFalse ( child. value as Any ? == nil )
You can’t perform that action at this time.
0 commit comments