Skip to content

Commit 7f5b838

Browse files
authored
exportobjects command (#74)
1 parent 8845a51 commit 7f5b838

2 files changed

Lines changed: 38 additions & 1 deletion

File tree

src/main/kotlin/file/CLICommand.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ enum class CLICommand {
1212
TYPECHECK,
1313
OUTDATED,
1414
BUILD,
15+
EXPORTOBJECTS,
1516
SELF_UPDATE
1617
}
1718

src/main/kotlin/file/SetupApp.kt

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ object SetupApp {
116116
}
117117
setup.command == CLICommand.TEST ||
118118
setup.command == CLICommand.TYPECHECK ||
119-
setup.command == CLICommand.BUILD -> {
119+
setup.command == CLICommand.BUILD ||
120+
setup.command == CLICommand.EXPORTOBJECTS -> {
120121
// Only needs to know a compiler is present; skip the version subprocess and update check.
121122
InstallationManager.verifyInstallation(probeVersion = false)
122123
}
@@ -149,6 +150,7 @@ object SetupApp {
149150
| typecheck Typecheck the project without building a map
150151
| outdated Check whether project dependencies are up to date
151152
| build <mapfile> Build the project using the given input map
153+
| exportobjects <mapfile|folder> Export object editor data to Wurst source
152154
|
153155
|Global options:
154156
| --quiet Suppress wurst output; only print errors and final result
@@ -271,6 +273,25 @@ object SetupApp {
271273
}
272274
}
273275
}
276+
setup.command == CLICommand.EXPORTOBJECTS -> {
277+
progress("Exporting object editor data...")
278+
val mapArg = if (setup.commandArg.isBlank()) {
279+
val maps = findMaps()
280+
when (maps.size) {
281+
0 -> { missingMap(); null }
282+
1 -> { log.info("Auto-detected map: ${maps[0].fileName}"); maps[0].fileName.toString() }
283+
else -> { multipleMaps(maps); null }
284+
}
285+
} else setup.commandArg
286+
if (mapArg != null) {
287+
val mapPath = setup.projectRoot.resolve(mapArg)
288+
if (!Files.exists(mapPath)) {
289+
missingMap(mapArg)
290+
} else if (InstallationManager.status != InstallationManager.InstallationStatus.NOT_INSTALLED) {
291+
exportObjects(mapPath)
292+
}
293+
}
294+
}
274295
setup.command == CLICommand.SELF_UPDATE -> {
275296
log.info("🔄 Updating...")
276297
try {
@@ -978,6 +999,21 @@ object SetupApp {
978999
}
9791000
}
9801001

1002+
private fun exportObjects(mapPath: Path) {
1003+
val args = ArrayList(InstallationManager.compilerLaunchCommand().toList())
1004+
args.add("-exportobjects")
1005+
args.add(mapPath.toAbsolutePath().toString())
1006+
1007+
val result = startWurstProcess(args)
1008+
when (result.exitCode) {
1009+
0 -> { pass("Object editor data exported."); ExitHandler.exit(0) }
1010+
else -> {
1011+
printCompilerFailure("exportobjects", result)
1012+
ExitHandler.exit(1)
1013+
}
1014+
}
1015+
}
1016+
9811017
private fun testProject(configData: WurstProjectConfigData) {
9821018
val args = commonArgs(configData)
9831019

0 commit comments

Comments
 (0)