Add --skip-errors flag to client import command

Signed-off-by: Graham <gpe@openrs2.org>
Graham 1 year ago
parent 774a92b289
commit 1083839720
  1. 33
      archive/src/main/kotlin/org/openrs2/archive/client/ClientImporter.kt
  2. 4
      archive/src/main/kotlin/org/openrs2/archive/client/ImportCommand.kt

@ -61,7 +61,13 @@ public class ClientImporter @Inject constructor(
private val packClassLibraryReader: PackClassLibraryReader, private val packClassLibraryReader: PackClassLibraryReader,
private val importer: CacheImporter private val importer: CacheImporter
) { ) {
public suspend fun import(paths: Iterable<Path>, name: String?, description: String?, url: String?) { public suspend fun import(
paths: Iterable<Path>,
name: String?,
description: String?,
url: String?,
skipErrors: Boolean
) {
alloc.buffer().use { buf -> alloc.buffer().use { buf ->
for (path in paths) { for (path in paths) {
buf.clear() buf.clear()
@ -73,14 +79,23 @@ public class ClientImporter @Inject constructor(
} }
logger.info { "Importing $path" } logger.info { "Importing $path" }
import( try {
parse(buf), import(
name, parse(buf),
description, name,
url, description,
path.fileName.toString(), url,
path.getLastModifiedTime().toInstant() path.fileName.toString(),
) path.getLastModifiedTime().toInstant()
)
} catch (t: Throwable) {
if (skipErrors) {
logger.warn(t) { "Failed to import $path" }
continue
}
throw t
}
} }
} }
} }

@ -3,6 +3,7 @@ package org.openrs2.archive.client
import com.github.ajalt.clikt.core.CliktCommand import com.github.ajalt.clikt.core.CliktCommand
import com.github.ajalt.clikt.parameters.arguments.argument import com.github.ajalt.clikt.parameters.arguments.argument
import com.github.ajalt.clikt.parameters.arguments.multiple import com.github.ajalt.clikt.parameters.arguments.multiple
import com.github.ajalt.clikt.parameters.options.flag
import com.github.ajalt.clikt.parameters.options.option import com.github.ajalt.clikt.parameters.options.option
import com.github.ajalt.clikt.parameters.types.path import com.github.ajalt.clikt.parameters.types.path
import com.google.inject.Guice import com.google.inject.Guice
@ -14,6 +15,7 @@ public class ImportCommand : CliktCommand(name = "import") {
private val name by option() private val name by option()
private val description by option() private val description by option()
private val url by option() private val url by option()
private val skipErrors by option().flag()
private val input by argument().path( private val input by argument().path(
mustExist = true, mustExist = true,
@ -24,7 +26,7 @@ public class ImportCommand : CliktCommand(name = "import") {
override fun run(): Unit = runBlocking { override fun run(): Unit = runBlocking {
CloseableInjector(Guice.createInjector(ArchiveModule)).use { injector -> CloseableInjector(Guice.createInjector(ArchiveModule)).use { injector ->
val importer = injector.getInstance(ClientImporter::class.java) val importer = injector.getInstance(ClientImporter::class.java)
importer.import(input, name, description, url) importer.import(input, name, description, url, skipErrors)
} }
} }
} }

Loading…
Cancel
Save