From 0139dfe0bfa06a13f56dc03e7718aaf644029614 Mon Sep 17 00:00:00 2001 From: SandaruKasa Date: Fri, 3 Nov 2023 03:31:45 +0300 Subject: [PATCH] feat: List patches which are compatible with any app (#297) Co-authored-by: oSumAtrIX --- .../app/revanced/cli/command/ListPatchesCommand.kt | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/app/revanced/cli/command/ListPatchesCommand.kt b/src/main/kotlin/app/revanced/cli/command/ListPatchesCommand.kt index 67e92c1..52b0e8c 100644 --- a/src/main/kotlin/app/revanced/cli/command/ListPatchesCommand.kt +++ b/src/main/kotlin/app/revanced/cli/command/ListPatchesCommand.kt @@ -42,6 +42,13 @@ internal object ListPatchesCommand : Runnable { ) 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( 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 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() }) }