Created
September 9, 2020 14:52
-
-
Save fortmarek/d714d151ab62fbd5040f12f533f4a1a0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension ArgumentSet { | |
init(_ type: ParsableArguments.Type) { | |
let a: [ArgumentSet] = Mirror(reflecting: type.init()) | |
.children | |
.compactMap { child in | |
guard | |
var codingKey = child.label, | |
let parsed = child.value as? ArgumentSetProvider | |
else { return nil } | |
// Property wrappers have underscore-prefixed names | |
codingKey = String(codingKey.first == "_" ? codingKey.dropFirst(1) : codingKey.dropFirst(0)) | |
let key = InputKey(rawValue: codingKey) | |
return parsed.argumentSet(for: key) | |
} | |
self.init(additive: a) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment