feat: List patches which are compatible with any app (#297)

Co-authored-by: oSumAtrIX <johan.melkonyan1@web.de>
This commit is contained in:
SandaruKasa 2023-11-03 03:31:45 +03:00 committed by GitHub
parent 7d1c0e663f
commit 0139dfe0bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -42,6 +42,13 @@ internal object ListPatchesCommand : Runnable {
) )
private var withOptions: Boolean = false private var withOptions: Boolean = false
@Option(
names = ["-u", "--with-universal-patches"],
description = ["List patches which are compatible with any app."],
showDefaultValue = ALWAYS
)
private var withUniversalPatches: Boolean = true
@Option( @Option(
names = ["-f", "--filter-package-name"], description = ["Filter patches by package name."] names = ["-f", "--filter-package-name"], description = ["Filter patches by package name."]
) )
@ -92,11 +99,12 @@ internal object ListPatchesCommand : Runnable {
} }
} }
fun Patch<*>.anyPackageName(name: String) = compatiblePackages?.any { it.name == name } == true fun Patch<*>.filterCompatiblePackages(name: String) = compatiblePackages?.any { it.name == name }
?: withUniversalPatches
val patches = PatchBundleLoader.Jar(*patchBundles) val patches = PatchBundleLoader.Jar(*patchBundles)
val filtered = packageName?.let { patches.filter { patch -> patch.anyPackageName(it) } } ?: patches val filtered = packageName?.let { patches.filter { patch -> patch.filterCompatiblePackages(it) } } ?: patches
if (filtered.isNotEmpty()) logger.info(filtered.joinToString("\n\n") { it.buildString() }) if (filtered.isNotEmpty()) logger.info(filtered.joinToString("\n\n") { it.buildString() })
} }