From a974b8ea80acd85f8dc472a3f93b8fd7bea08007 Mon Sep 17 00:00:00 2001 From: oSumAtrIX Date: Mon, 27 Nov 2023 23:11:23 +0100 Subject: [PATCH 1/4] feat: Add `list-versions` command --- gradle/libs.versions.toml | 2 +- .../cli/command/ListCompatibleVersions.kt | 67 +++++++++++++++++++ .../app/revanced/cli/command/MainCommand.kt | 3 +- 3 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 src/main/kotlin/app/revanced/cli/command/ListCompatibleVersions.kt diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index f70eea1..766c44d 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -4,7 +4,7 @@ kotlin-test = "1.9.20" kotlinx-coroutines-core = "1.7.3" picocli = "4.7.3" revanced-patcher = "19.0.0" -revanced-library = "1.3.0" +revanced-library = "1.4.0" [libraries] kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotlin-test" } diff --git a/src/main/kotlin/app/revanced/cli/command/ListCompatibleVersions.kt b/src/main/kotlin/app/revanced/cli/command/ListCompatibleVersions.kt new file mode 100644 index 0000000..ab21eee --- /dev/null +++ b/src/main/kotlin/app/revanced/cli/command/ListCompatibleVersions.kt @@ -0,0 +1,67 @@ +package app.revanced.cli.command + +import app.revanced.library.PackageName +import app.revanced.library.PatchUtils +import app.revanced.library.VersionMap +import app.revanced.patcher.PatchBundleLoader +import picocli.CommandLine +import java.io.File +import java.util.logging.Logger + +@CommandLine.Command( + name = "list-versions", + description = [ + "List the most common compatible versions of apps that are compatible " + + "with the patches in the supplied patch bundles.", + ], +) +internal class ListCompatibleVersions : Runnable { + private val logger = Logger.getLogger(ListCompatibleVersions::class.java.name) + + @CommandLine.Parameters( + description = ["Paths to patch bundles."], + arity = "1..*", + ) + private lateinit var patchBundles: Array + + @CommandLine.Option( + names = ["-f", "--filter-package-names"], + description = ["Filter patches by package name."], + ) + private var packageNames: Set? = null + + @CommandLine.Option( + names = ["-u", "--count-unused-patches"], + description = ["Count patches that are not used by default."], + showDefaultValue = CommandLine.Help.Visibility.ALWAYS, + ) + private var countUnusedPatches: Boolean = false + + override fun run() { + val patches = PatchBundleLoader.Jar(*patchBundles) + + fun VersionMap.buildVersionsString(): String { + if (isEmpty()) return "Any" + + fun buildPatchesCountString(count: Int) = if (count == 1) "1 patch" else "$count patches" + + return entries.joinToString("\n") { (version, count) -> + "$version (${buildPatchesCountString(count)})" + } + } + + fun buildString(entry: Map.Entry) = + buildString { + val (name, versions) = entry + appendLine("Package name: $name") + appendLine("Most common compatible versions:") + appendLine(versions.buildVersionsString().prependIndent("\t")) + } + + PatchUtils.getMostCommonCompatibleVersions( + patches, + packageNames, + countUnusedPatches, + ).entries.joinToString("\n", transform = ::buildString).let(logger::info) + } +} diff --git a/src/main/kotlin/app/revanced/cli/command/MainCommand.kt b/src/main/kotlin/app/revanced/cli/command/MainCommand.kt index 7a76097..4d33a4d 100644 --- a/src/main/kotlin/app/revanced/cli/command/MainCommand.kt +++ b/src/main/kotlin/app/revanced/cli/command/MainCommand.kt @@ -33,9 +33,10 @@ private object CLIVersionProvider : IVersionProvider { mixinStandardHelpOptions = true, versionProvider = CLIVersionProvider::class, subcommands = [ - ListPatchesCommand::class, PatchCommand::class, OptionsCommand::class, + ListPatchesCommand::class, + ListCompatibleVersions::class, UtilityCommand::class, ], ) From 06c6a979154e299e987ad0453bc74f43c966521a Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Mon, 27 Nov 2023 22:12:44 +0000 Subject: [PATCH 2/4] chore(release): 4.3.0-dev.1 [skip ci] # [4.3.0-dev.1](https://github.com/ReVanced/revanced-cli/compare/v4.2.0...v4.3.0-dev.1) (2023-11-27) ### Features * Add `list-versions` command ([a974b8e](https://github.com/ReVanced/revanced-cli/commit/a974b8ea80acd85f8dc472a3f93b8fd7bea08007)) --- CHANGELOG.md | 7 +++++++ gradle.properties | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 555a1d6..fee3925 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +# [4.3.0-dev.1](https://github.com/ReVanced/revanced-cli/compare/v4.2.0...v4.3.0-dev.1) (2023-11-27) + + +### Features + +* Add `list-versions` command ([a974b8e](https://github.com/ReVanced/revanced-cli/commit/a974b8ea80acd85f8dc472a3f93b8fd7bea08007)) + # [4.2.0](https://github.com/ReVanced/revanced-cli/compare/v4.1.0...v4.2.0) (2023-11-26) diff --git a/gradle.properties b/gradle.properties index bf444fa..b762d0e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ org.gradle.parallel = true org.gradle.caching = true kotlin.code.style = official -version = 4.2.0 +version = 4.3.0-dev.1 From 5e089ea9af2b82978cf6dbe8204822789b0bebf7 Mon Sep 17 00:00:00 2001 From: oSumAtrIX Date: Fri, 1 Dec 2023 01:12:26 +0100 Subject: [PATCH 3/4] docs: Update to latest GitHub Markdown syntax changes --- docs/1_usage.md | 102 ++++++++++++++++++++++++------------------------ 1 file changed, 51 insertions(+), 51 deletions(-) diff --git a/docs/1_usage.md b/docs/1_usage.md index 075a3ad..94c878e 100644 --- a/docs/1_usage.md +++ b/docs/1_usage.md @@ -34,39 +34,39 @@ ReVanced CLI is divided into the following fundamental commands: revanced-patches.jar [ ...] ``` - > [!NOTE] - > A default `options.json` file will be automatically created, if it does not exist - without any need for intervention when using the `patch` command. +> [!NOTE] +> A default `options.json` file will be automatically created, if it does not exist +without any need for intervention when using the `patch` command. - ### 💉 Patch an app You can patch apps by supplying patch bundles and the app to patch. After patching, ReVanced CLI can install the patched app on your device using two methods: - > [!NOTE] - > For ReVanced CLI to be able to install the patched app on your device, make sure ADB is working: - > - > ```bash - > adb shell exit - > ``` - > - > To get your device's serial, run the following command: - > - > ```bash - > adb devices - > ``` - > - > If you want to mount the patched app on top of the un-patched app, make sure you have root permissions: - > - > ```bash - > adb shell su -c exit - > ``` - > +> [!NOTE] +> For ReVanced CLI to be able to install the patched app on your device, make sure ADB is working: +> +> ```bash +> adb shell exit +> ``` +> +> To get your device's serial, run the following command: +> +> ```bash +> adb devices +> ``` +> +> If you want to mount the patched app on top of the un-patched app, make sure you have root permissions: +> +> ```bash +> adb shell su -c exit +> ``` +> - > [!WARNING] - > Some patches may require integrations - > such as [ReVanced Integrations](https://github.com/revanced/revanced-integrations). - > Supply them with the option `--merge`. ReVanced Patcher will automatically determine if they are necessary. +> [!WARNING] +> Some patches may require integrations +> such as [ReVanced Integrations](https://github.com/revanced/revanced-integrations). +> Supply them with the option `--merge`. ReVanced Patcher will automatically determine if they are necessary. - #### 👾 Patch an app and install it on your device regularly @@ -79,26 +79,26 @@ ReVanced CLI is divided into the following fundamental commands: - #### 👾 Patch an app and mount it on top of the un-patched app with root permissions - > [!IMPORTANT] - > Ensure sure the same app you are patching and mounting over is installed on your device: - > - > ```bash - > adb install app.apk - > ``` + > [!IMPORTANT] + > Ensure sure the same app you are patching and mounting over is installed on your device: + > + > ```bash + > adb install app.apk + > ``` - > [!NOTE] - > You can use the option `--ii` to include or `--ie` to exclude - > patches by their index in relation to supplied patch bundles, - > similarly to the option `--include` and `--exclude`. - > - > This is useful in case two patches have the same name, and you need to include or exclude one of them. - > The index of a patch is calculated by the position of the patch in the list of patches - > from patch bundles supplied using the option `--patch-bundle`. - > - > You can list all patches with their indices using the command `list-patches`. - > - > Keep in mind, that the indices can change based on the order of the patch bundles supplied, - > as well if the patch bundles are updated, because patches can be added or removed. + > [!NOTE] + > You can use the option `--ii` to include or `--ie` to exclude + > patches by their index in relation to supplied patch bundles, + > similarly to the option `--include` and `--exclude`. + > + > This is useful in case two patches have the same name, and you need to include or exclude one of them. + > The index of a patch is calculated by the position of the patch in the list of patches + > from patch bundles supplied using the option `--patch-bundle`. + > + > You can list all patches with their indices using the command `list-patches`. + > + > Keep in mind, that the indices can change based on the order of the patch bundles supplied, + > as well if the patch bundles are updated, because patches can be added or removed. ```bash java -jar revanced-cli.jar patch \ @@ -119,9 +119,9 @@ ReVanced CLI is divided into the following fundamental commands: [] ``` - > [!NOTE] - > You can unmount an APK file - by adding the option `--unmount`. +> [!NOTE] +> You can unmount an APK file +by adding the option `--unmount`. - ### ️ 📦 Install an app @@ -131,6 +131,6 @@ ReVanced CLI is divided into the following fundamental commands: [] ``` - > [!NOTE] - > You can mount an APK file - > by supplying the package name of the app to mount the supplied APK file to over the option `--mount`. +> [!NOTE] +> You can mount an APK file +> by supplying the package name of the app to mount the supplied APK file to over the option `--mount`. From ab7d9d8e1eb53012ed6421374fcfb308672d6b89 Mon Sep 17 00:00:00 2001 From: oSumAtrIX Date: Fri, 1 Dec 2023 01:21:32 +0100 Subject: [PATCH 4/4] build: Bump dependencies --- gradle/libs.versions.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 766c44d..af1fe12 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -3,7 +3,7 @@ shadow = "8.1.1" kotlin-test = "1.9.20" kotlinx-coroutines-core = "1.7.3" picocli = "4.7.3" -revanced-patcher = "19.0.0" +revanced-patcher = "19.1.0" revanced-library = "1.4.0" [libraries]