Skip to content

Instantly share code, notes, and snippets.

@fortmarek
Created September 9, 2020 14:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fortmarek/d714d151ab62fbd5040f12f533f4a1a0 to your computer and use it in GitHub Desktop.
Save fortmarek/d714d151ab62fbd5040f12f533f4a1a0 to your computer and use it in GitHub Desktop.
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