feat: Add option to filter patches to be listed by package name

This commit is contained in:
oSumAtrIX 2023-09-22 02:35:43 +02:00
parent 77d91735ff
commit 50c0f98ce5
No known key found for this signature in database
GPG Key ID: A9B3094ACDB604B4
2 changed files with 13 additions and 2 deletions

View File

@ -42,6 +42,11 @@ internal object ListPatchesCommand : Runnable {
)
private var withOptions: Boolean = false
@Option(
names = ["-f", "--filter-package-name"], description = ["Filter patches by package name"]
)
private var packageName: String? = null
override fun run() {
fun Patch.CompatiblePackage.buildString() = buildString {
if (withVersions && versions != null) {
@ -83,6 +88,12 @@ internal object ListPatchesCommand : Runnable {
}
}
logger.info(PatchBundleLoader.Jar(*patchBundles).joinToString("\n\n") { it.buildString() })
fun Patch<*>.anyPackageName(name: String) = compatiblePackages?.any { it.name == name } == true
val patches = PatchBundleLoader.Jar(*patchBundles)
val filtered = packageName?.let { patches.filter { patch -> patch.anyPackageName(it) } } ?: patches
if (filtered.isNotEmpty()) logger.info(filtered.joinToString("\n\n") { it.buildString() })
}
}

View File

@ -23,7 +23,7 @@ internal object PatchUtilsTest {
@Test
fun `return null because no patch is compatible with the supplied package name`() {
val patches = setOf(newPatch("other.package", "a"))
val patches = setOf(newPatch("some.package", "a"))
assertEqualsVersion(null, patches, "other.package")
}