Skip to content

Commit ae377e2

Browse files
author
Harald
committed
Force single target selection on command line
1 parent 4d9f5d7 commit ae377e2

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

Plugins/GeneratorCommand/ObjectBoxCommand.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ struct GeneratorCommand: CommandPlugin {
6161

6262
// keep for now as a reminder to check if we process args, or not
6363
let tool = try context.tool(named: "objectbox-generator")
64-
print("Processing arguments: \(arguments)")
64+
print("Processing arguments:: \(arguments)")
6565
if arguments.count == 1 {
6666
if arguments[0] == "context" {
6767
dump(context)
@@ -78,6 +78,14 @@ struct GeneratorCommand: CommandPlugin {
7878
? context.package.targets
7979
: try context.package.targets(named: targetNames)
8080

81+
// Since the generator generates code even for targets that have no ObjectBox annotations at all,
82+
// restrict the target to not generate code for targets like tests ...
83+
if targets.count > 1 {
84+
let targetNames = targets.map { $0.name }.joined(separator: ", ")
85+
Diagnostics.error("Multiple targets found\nPlease select specify one target by using the `--target name` option\nAvailable target names: \(targetNames)")
86+
return
87+
}
88+
8189
for target in targets {
8290
guard let target = target.sourceModule else { continue }
8391

0 commit comments

Comments
 (0)