This repository has been archived by the owner on Mar 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: use separate command to list patches
- Loading branch information
Showing
4 changed files
with
113 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
src/main/kotlin/app/revanced/cli/command/ListPatchesCommand.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
package app.revanced.cli.command | ||
|
||
import app.revanced.patcher.PatchBundleLoader | ||
import app.revanced.patcher.annotation.Package | ||
import app.revanced.patcher.extensions.PatchExtensions.compatiblePackages | ||
import app.revanced.patcher.extensions.PatchExtensions.description | ||
import app.revanced.patcher.extensions.PatchExtensions.options | ||
import app.revanced.patcher.extensions.PatchExtensions.patchName | ||
import app.revanced.patcher.patch.PatchClass | ||
import app.revanced.patcher.patch.PatchOption | ||
import picocli.CommandLine | ||
import picocli.CommandLine.Help.Visibility.ALWAYS | ||
import java.io.File | ||
|
||
|
||
@CommandLine.Command(name = "list-patches", description = ["List patches from supplied patch bundles"]) | ||
class ListPatchesCommand : Runnable { | ||
@CommandLine.Parameters( | ||
description = ["Paths to patch bundles"], | ||
arity = "1..*" | ||
) | ||
lateinit var patchBundles: Array<File> | ||
|
||
@CommandLine.Option( | ||
names = ["-d", "--with-descriptions"], | ||
description = ["List their descriptions"], | ||
showDefaultValue = ALWAYS | ||
) | ||
var withDescriptions: Boolean = true | ||
|
||
@CommandLine.Option( | ||
names = ["-p", "--with-packages"], | ||
description = ["List the packages the patches are compatible with"], | ||
showDefaultValue = ALWAYS | ||
) | ||
var withPackages: Boolean = false | ||
|
||
@CommandLine.Option( | ||
names = ["-v", "--with-versions"], | ||
description = ["List the versions of the packages the patches are compatible with"], | ||
showDefaultValue = ALWAYS | ||
) | ||
var withVersions: Boolean = false | ||
|
||
@CommandLine.Option( | ||
names = ["-o", "--with-options"], | ||
description = ["List the options of the patches"], | ||
showDefaultValue = ALWAYS | ||
) | ||
var withOptions: Boolean = false | ||
|
||
override fun run() { | ||
fun Package.buildString() = buildString { | ||
if (withVersions && versions.isNotEmpty()) { | ||
appendLine("Package name: $name") | ||
appendLine("Compatible versions:") | ||
append(versions.joinToString("\n") { version -> version }.prependIndent("\t")) | ||
} else | ||
append("Package name: $name") | ||
} | ||
|
||
fun PatchOption<*>.buildString() = buildString { | ||
appendLine("Title: $title") | ||
appendLine("Description: $description") | ||
|
||
value?.let { | ||
appendLine("Key: $key") | ||
append("Value: $it") | ||
} ?: append("Key: $key") | ||
} | ||
|
||
fun PatchClass.buildString() = buildString { | ||
append("Name: $patchName") | ||
|
||
if (withDescriptions) append("\nDescription: $description") | ||
|
||
if (withOptions && options != null) { | ||
appendLine("\nOptions:") | ||
append( | ||
options!!.joinToString("\n\n") { option -> option.buildString() }.prependIndent("\t") | ||
) | ||
} | ||
|
||
if (withPackages && compatiblePackages != null) { | ||
appendLine("\nCompatible packages:") | ||
append( | ||
compatiblePackages!!.joinToString("\n") { it.buildString() }.prependIndent("\t") | ||
) | ||
} | ||
} | ||
|
||
MainCommand.logger.info(PatchBundleLoader.Jar(*patchBundles).joinToString("\n\n") { it.buildString() }) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.