This file contains hidden or 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
static var attributes: [String] = [] | |
static func preprocess(_ arguments: [String]) throws { | |
... | |
let attributes: [String] = try JSONDecoder().decode([String].self, from: data) | |
Scaffold.attributes = attributes | |
} |
This file contains hidden or 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 Scaffold: CustomReflectable { | |
var customMirror: Mirror { | |
// #1 | |
let attributesChildren: [Mirror.Child] = Scaffold.attributes | |
// #2 | |
.map { | |
(name: $0, option: Option<String>(name: .shortAndLong)) | |
} | |
// #3 | |
.map { |
This file contains hidden or 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
@Option(name: .shortAndLong) | |
var name: String |
This file contains hidden or 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
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 |
This file contains hidden or 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
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) |
This file contains hidden or 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
func run() throws { | |
print(template) | |
print(attributes) | |
} |
OlderNewer