Skip to content

Commit

Permalink
feat: separate options for --list (ReVanced#60)
Browse files Browse the repository at this point in the history
  • Loading branch information
EdgE790 authored Jul 3, 2022
1 parent 75e9c49 commit 52b3161
Showing 1 changed file with 42 additions and 3 deletions.
45 changes: 42 additions & 3 deletions src/main/kotlin/app/revanced/cli/command/MainCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import app.revanced.cli.patcher.logging.impl.PatcherLogger
import app.revanced.cli.signing.Signing
import app.revanced.cli.signing.SigningOptions
import app.revanced.patcher.PatcherOptions
import app.revanced.patcher.extensions.PatchExtensions.compatiblePackages
import app.revanced.patcher.extensions.PatchExtensions.description
import app.revanced.patcher.extensions.PatchExtensions.patchName
import app.revanced.patcher.util.patch.implementation.JarPatchBundle
Expand Down Expand Up @@ -45,6 +46,15 @@ internal object MainCommand : Runnable {
class ListingArgs {
@Option(names = ["-l", "--list"], description = ["List patches only"], required = true)
var listOnly: Boolean = false

@Option(names = ["--with-versions"], description = ["List patches with compatible versions"])
var withVersions: Boolean = false

@Option(names = ["--with-packages"], description = ["List patches with compatible packages"])
var withPackages: Boolean = false

@Option(names = ["--with-descriptions"], description = ["List patches with their descriptions"])
var withDescriptions: Boolean = true
}

class PatchingArgs {
Expand Down Expand Up @@ -96,9 +106,7 @@ internal object MainCommand : Runnable {

override fun run() {
if (args.lArgs?.listOnly == true) {
for (patchBundlePath in args.patchBundles) for (patch in JarPatchBundle(patchBundlePath).loadPatches()) {
logger.info("${patch.patchName}: ${patch.description}")
}
printListOfPatches()
return
}

Expand Down Expand Up @@ -146,4 +154,35 @@ internal object MainCommand : Runnable {

logger.info("Finished")
}

private fun printListOfPatches() {
for (patchBundlePath in args.patchBundles) for (patch in JarPatchBundle(patchBundlePath).loadPatches()) {
for (compatiblePackage in patch.compatiblePackages!!) {
val packageEntryStr = buildString {
// Add package if flag is set
if (args.lArgs?.withPackages == true) {
val packageName = compatiblePackage.name.substringAfterLast(".").padStart(10)
append(packageName)
append("\t")
}
// Add patch name
val patchName = patch.patchName.padStart(25)
append(patchName)
// Add description if flag is set.
if (args.lArgs?.withDescriptions == true) {
append("\t")
append(patch.description)
}
// Add compatible versions, if flag is set
if (args.lArgs?.withVersions == true) {
val compatibleVersions = compatiblePackage.versions.joinToString(separator = ", ")
append("\t")
append(compatibleVersions)
}

}
logger.info(packageEntryStr)
}
}
}
}

0 comments on commit 52b3161

Please sign in to comment.