mirror of
https://github.com/revanced/revanced-cli.git
synced 2024-12-11 12:47:46 +01:00
feat: Add list-versions
command
This commit is contained in:
parent
89c35ee21b
commit
a974b8ea80
@ -4,7 +4,7 @@ kotlin-test = "1.9.20"
|
|||||||
kotlinx-coroutines-core = "1.7.3"
|
kotlinx-coroutines-core = "1.7.3"
|
||||||
picocli = "4.7.3"
|
picocli = "4.7.3"
|
||||||
revanced-patcher = "19.0.0"
|
revanced-patcher = "19.0.0"
|
||||||
revanced-library = "1.3.0"
|
revanced-library = "1.4.0"
|
||||||
|
|
||||||
[libraries]
|
[libraries]
|
||||||
kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotlin-test" }
|
kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotlin-test" }
|
||||||
|
@ -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<File>
|
||||||
|
|
||||||
|
@CommandLine.Option(
|
||||||
|
names = ["-f", "--filter-package-names"],
|
||||||
|
description = ["Filter patches by package name."],
|
||||||
|
)
|
||||||
|
private var packageNames: Set<String>? = 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<PackageName, VersionMap>) =
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
}
|
@ -33,9 +33,10 @@ private object CLIVersionProvider : IVersionProvider {
|
|||||||
mixinStandardHelpOptions = true,
|
mixinStandardHelpOptions = true,
|
||||||
versionProvider = CLIVersionProvider::class,
|
versionProvider = CLIVersionProvider::class,
|
||||||
subcommands = [
|
subcommands = [
|
||||||
ListPatchesCommand::class,
|
|
||||||
PatchCommand::class,
|
PatchCommand::class,
|
||||||
OptionsCommand::class,
|
OptionsCommand::class,
|
||||||
|
ListPatchesCommand::class,
|
||||||
|
ListCompatibleVersions::class,
|
||||||
UtilityCommand::class,
|
UtilityCommand::class,
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user