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 {
208208 }
209209}
210210
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.
211230protocol ArgumentSetProvider {
212231 func argumentSet( for key: InputKey ) -> ArgumentSet
213232}
@@ -241,7 +260,7 @@ extension ArgumentSet {
241260 key: InputKey ( rawValue: codingKey) ,
242261 kind: . default,
243262 parser: { _ in nil } ,
244- default: Mirror . realValue ( for : child) ,
263+ default: nilOrValue ( child. value ) ,
245264 completion: . default)
246265 definition. help. help = . hidden
247266 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 {
2929 }
3030 XCTAssertEqual ( stringValue, expectedString)
3131 } else {
32- XCTAssertNil ( Mirror . realValue ( for : child) )
32+ XCTAssertNil ( nilOrValue ( child. value ) )
3333 // This is why we use `unwrapedOptionalValue` for optionality checks
3434 // Even though the `value` is `nil` this returns `false`
3535 XCTAssertFalse ( child. value as Any ? == nil )
You can’t perform that action at this time.
0 commit comments