Skip to content

Instantly share code, notes, and snippets.

View fortmarek's full-sized avatar
💭
🙂

Marek Fořt fortmarek

💭
🙂
View GitHub Profile
static var attributes: [String] = []
static func preprocess(_ arguments: [String]) throws {
...
let attributes: [String] = try JSONDecoder().decode([String].self, from: data)
Scaffold.attributes = attributes
}
extension Scaffold: CustomReflectable {
var customMirror: Mirror {
// #1
let attributesChildren: [Mirror.Child] = Scaffold.attributes
// #2
.map {
(name: $0, option: Option<String>(name: .shortAndLong))
}
// #3
.map {
@Option(name: .shortAndLong)
var name: String
enum CodingKeys: String, CodingKey {
case template
}
init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
template = try container.decode(Argument<String>.self, forKey: .template).wrappedValue
}
// Necessary for conforming ParsableArguments
enum CodingKeys: CodingKey {
case template
case dynamic(String)
init?(stringValue: String) {
switch stringValue {
case "template":
self = .template
case stringValue where Scaffold.attributes.contains(stringValue):
self = .dynamic(stringValue)
func run() throws {
print(template)
print(attributes)
}