@@ -13,36 +13,35 @@ import SwiftSyntax
1313struct GenerateCommand : AsyncParsableCommand {
1414 static let configuration = CommandConfiguration ( commandName: " generate " )
1515
16- @Option ( name: . shortAndLong, help: " The root directory of the Otter sources " )
16+ @Option ( name: . shortAndLong, help: " The directory containing the otter.yaml " )
1717 var path : String = FileManager . default. currentDirectoryPath
1818
19- @Option ( name: . shortAndLong, help: " The output file path. Default is to stdout " )
20- var output : String ? = nil
21-
22- @Option ( name: . shortAndLong, help: " The database name " )
23- var databaseName : String = " DB "
24-
25- @Option ( name: . shortAndLong, help: " Comma separated list of additional imports to add " )
26- var additionalImports : String ?
27-
2819 @Flag ( help: " If set, any diagnostic message will not be colorized " )
2920 var dontColorize = false
3021
3122 @Flag ( help: " If set, core parts of the compilation will be timed " )
3223 var time = false
3324
3425 mutating func run( ) async throws {
26+ let config = try Config . load ( at: path)
27+ let project = config. project ( at: path)
28+
3529 let options = GenerationOptions (
36- databaseName: databaseName,
37- imports: additionalImports ? . split ( separator : " , " ) . map ( \ . description ) ?? [ ]
30+ databaseName: config . databaseName ?? " DB " ,
31+ imports: config . additionalImports ?? [ ]
3832 )
3933
40- try await generate ( language: SwiftLanguage . self, options: options)
34+ try await generate (
35+ language: SwiftLanguage . self,
36+ options: options,
37+ project: project
38+ )
4139 }
4240
4341 private func generate< Lang: Language > (
4442 language: Lang . Type ,
45- options: GenerationOptions
43+ options: GenerationOptions ,
44+ project: Project
4645 ) async throws {
4746 let driver = Driver ( )
4847 await driver. logTimes ( time)
@@ -51,12 +50,17 @@ struct GenerateCommand: AsyncParsableCommand {
5150 reporter: StdoutDiagnosticReporter ( dontColorize: dontColorize)
5251 )
5352
54- try await driver. compile ( path: path)
53+ try await driver. compile (
54+ migrationsPath: project. migrationsDirectory. path,
55+ queriesPath: project. queriesDirectory. path
56+ )
5557
5658 try await driver. generate (
5759 language: Lang . self,
58- to: output ,
60+ to: project . generatedOutputFile . path ,
5961 options: options
6062 )
63+
64+ print ( " Generated output to \( project. generatedOutputFile. path) " )
6165 }
6266}
0 commit comments