@@ -37,21 +37,38 @@ struct GeneratorCommand: CommandPlugin {
3737 return " generated/EntityInfo- \( targetName) .generated.swift "
3838 }
3939
40+ // Removes the `--target` option and its value from the arguments array
41+ // This is needed because the `--target` option is not recognized by the Sourcery executable
42+ private func removeTargetNameFromArgs( _ args: [ String ] ) -> [ String ] {
43+ var filteredArgs = args
44+ if let targetIndex = filteredArgs. firstIndex ( of: " --target " ) {
45+ // Remove --target and the following value (target name)
46+ filteredArgs. remove ( at: targetIndex)
47+ if targetIndex < filteredArgs. count {
48+ filteredArgs. remove ( at: targetIndex)
49+ }
50+ }
51+ return filteredArgs
52+ }
53+
4054 private func runGenerator(
41- generator: PluginContext . Tool , targetPath: Path , codeFilePath: String , modelFilePath: String
55+ generator: PluginContext . Tool , targetPath: Path , codeFilePath: String , modelFilePath: String ,
56+ args: [ String ] = [ ]
4257 ) {
4358 let modelFileTargetPath = targetPath. appending ( modelFilePath) . string
4459 let codeFileTargetPath = targetPath. appending ( codeFilePath) . string
4560
61+ // The generator does not support the --target argument and would error, remove it
62+ let filteredArgs = removeTargetNameFromArgs ( args)
63+
4664 // Specify --sources for Xcode project setup as well, Sourcery does not seem able to detect Xcode project
47- let args : [ String ] = [
48- " --sources " , targetPath. string,
49- " --model-json " , modelFileTargetPath,
50- " --output " , codeFileTargetPath,
51- " --disableCache " ,
52- " --verbose " ,
53- " --no-statistics " ,
54- ]
65+ let args : [ String ] =
66+ [
67+ " --sources " , targetPath. string,
68+ " --model-json " , modelFileTargetPath,
69+ " --output " , codeFileTargetPath,
70+ " --disableCache " ,
71+ ] + filteredArgs
5572
5673 runGenerator ( generator: generator, args: args)
5774 }
@@ -149,7 +166,7 @@ struct GeneratorCommand: CommandPlugin {
149166 let modelFilePath = buildModelJsonFilePath ( targetName: target. name)
150167 runGenerator (
151168 generator: tool, targetPath: targetPath, codeFilePath: codeFilePath,
152- modelFilePath: modelFilePath)
169+ modelFilePath: modelFilePath, args : arguments )
153170 }
154171 }
155172}
@@ -186,7 +203,7 @@ struct GeneratorCommand: CommandPlugin {
186203 // the generator and let it find source files.
187204 runGenerator (
188205 generator: tool, targetPath: targetPath, codeFilePath: codeFilePath,
189- modelFilePath: modelFilePath)
206+ modelFilePath: modelFilePath, args : arguments )
190207
191208 // TODO Add the generated files to the Xcode project
192209 Diagnostics . remark (
0 commit comments