@@ -12,42 +12,22 @@ import SwiftSyntax
1212
1313@main
1414struct Feather : AsyncParsableCommand {
15- @Option ( name: . shortAndLong, help: " The root directory of the Feather sources " )
16- var path : String = FileManager . default. currentDirectoryPath
17-
18- @Option ( name: . shortAndLong, help: " The output file path. Default is to stdout " )
19- var output : String ? = nil
20-
21- @Option ( name: . shortAndLong, help: " The database name " )
22- var databaseName : String = " DB "
23-
24- @Option ( name: . shortAndLong, help: " Comma separated list of additional imports to add " )
25- var additionalImports : String ?
26-
27- @Flag var dontColorize = false
28-
29- mutating func run( ) async throws {
30- let options = GenerationOptions (
31- databaseName: databaseName,
32- imports: additionalImports? . split ( separator: " , " ) . map ( \. description) ?? [ ]
33- )
34-
35- try await generate ( language: SwiftLanguage . self, options: options)
36- }
15+ static let configuration = CommandConfiguration (
16+ subcommands: [ GenCommand . self, InitCommand . self, MigrateCommand . self, QueriesCommand . self] ,
17+ defaultSubcommand: GenCommand . self
18+ )
19+ }
20+
21+ enum FeatherError : Error , CustomStringConvertible {
22+ case sourcesNotFound
23+ case queryAlreadyExists( fileName: String )
3724
38- private func generate< Lang: Language > (
39- language: Lang . Type ,
40- options: GenerationOptions
41- ) async throws {
42- let driver = Driver ( )
43- await driver. add ( reporter: StdoutDiagnosticReporter ( dontColorize: dontColorize) )
44-
45- try await driver. compile ( path: path)
46-
47- try await driver. generate (
48- language: Lang . self,
49- to: output,
50- options: options
51- )
25+ var description : String {
26+ switch self {
27+ case . sourcesNotFound:
28+ " Sources not found, run init to initialize new project "
29+ case . queryAlreadyExists( let fileName) :
30+ " Query file with name ' \( fileName) ' already exists "
31+ }
5232 }
5333}
0 commit comments