Skip to content
This repository has been archived by the owner on Apr 15, 2024. It is now read-only.

Commit

Permalink
feat: add install command
Browse files Browse the repository at this point in the history
This introduces a separate utility subcommand.
  • Loading branch information
oSumAtrIX committed Aug 24, 2023
1 parent a3d8705 commit 0350b7f
Show file tree
Hide file tree
Showing 9 changed files with 156 additions and 142 deletions.
18 changes: 16 additions & 2 deletions docs/1_usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,26 @@ Learn how to ReVanced CLI.
> **Note**: Some patches may require integrations
such as [ReVanced Integrations](https://github.com/revanced/revanced-integrations).
Supply them with the option `-m`. If any patches accepted by ReVanced Patcher require ReVanced Integrations,
Supply them with the option `--merge`. If any patches accepted by ReVanced Patcher require ReVanced Integrations,
they will be merged into the APK file automatically.
- ### 🗑️ Uninstall a patched APK file
```bash
java -jar revanced-cli.jar uninstall \
java -jar revanced-cli.jar utility uninstall \
--package-name <package-name> \
<device-serial>
```
> **Note**: You can unmount an APK file
with the option `--unmount`.
- ### ️ ⚙️ Manually install an APK file
```bash
java -jar revanced-cli.jar utility install \
-a input.apk \
<device-serial>
```
> **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`.
26 changes: 10 additions & 16 deletions src/main/kotlin/app/revanced/cli/command/ListPatchesCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,47 +19,41 @@ internal object ListPatchesCommand : Runnable {
private val logger = Logger.getLogger(ListPatchesCommand::class.java.name)

@Parameters(
description = ["Paths to patch bundles"],
arity = "1..*"
description = ["Paths to patch bundles"], arity = "1..*"
)
lateinit var patchBundles: Array<File>
private lateinit var patchBundles: Array<File>

@Option(
names = ["-d", "--with-descriptions"],
description = ["List their descriptions"],
showDefaultValue = ALWAYS
names = ["-d", "--with-descriptions"], description = ["List their descriptions"], showDefaultValue = ALWAYS
)
var withDescriptions: Boolean = true
private var withDescriptions: Boolean = true

@Option(
names = ["-p", "--with-packages"],
description = ["List the packages the patches are compatible with"],
showDefaultValue = ALWAYS
)
var withPackages: Boolean = false
private var withPackages: Boolean = false

@Option(
names = ["-v", "--with-versions"],
description = ["List the versions of the packages the patches are compatible with"],
description = ["List the versions of the apps the patches are compatible with"],
showDefaultValue = ALWAYS
)
var withVersions: Boolean = false
private var withVersions: Boolean = false

@Option(
names = ["-o", "--with-options"],
description = ["List the options of the patches"],
showDefaultValue = ALWAYS
names = ["-o", "--with-options"], description = ["List the options of the patches"], showDefaultValue = ALWAYS
)
var withOptions: Boolean = false
private 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")
} else append("Package name: $name")
}

fun PatchOption<*>.buildString() = buildString {
Expand Down
7 changes: 4 additions & 3 deletions src/main/kotlin/app/revanced/cli/command/MainCommand.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package app.revanced.cli.command

import app.revanced.cli.command.utility.UtilityCommand
import app.revanced.patcher.patch.PatchClass
import picocli.CommandLine
import picocli.CommandLine.Command
Expand Down Expand Up @@ -42,7 +43,7 @@ fun main(args: Array<String>) {

internal typealias PatchList = List<PatchClass>

object CLIVersionProvider : IVersionProvider {
private object CLIVersionProvider : IVersionProvider {
override fun getVersion(): Array<String> {
Properties().apply {
load(MainCommand::class.java.getResourceAsStream("/app/revanced/cli/version.properties"))
Expand All @@ -60,8 +61,8 @@ object CLIVersionProvider : IVersionProvider {
subcommands = [
ListPatchesCommand::class,
PatchCommand::class,
UninstallCommand::class,
OptionsCommand::class,
UtilityCommand::class,
]
)
internal object MainCommand
private object MainCommand
29 changes: 11 additions & 18 deletions src/main/kotlin/app/revanced/cli/command/OptionsCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,38 +16,31 @@ internal object OptionsCommand : Runnable {
private val logger = Logger.getLogger(OptionsCommand::class.java.name)

@CommandLine.Parameters(
description = ["Paths to patch bundles"],
arity = "1..*"
description = ["Paths to patch bundles"], arity = "1..*"
)
lateinit var patchBundles: Array<File>
private lateinit var patchBundles: Array<File>

@CommandLine.Option(
names = ["-p", "--path"],
description = ["Path to patch options JSON file"],
showDefaultValue = ALWAYS
names = ["-p", "--path"], description = ["Path to patch options JSON file"], showDefaultValue = ALWAYS
)
var path: File = File("options.json")
private var path: File = File("options.json")

@CommandLine.Option(
names = ["-o", "--overwrite"],
description = ["Overwrite existing options file"],
showDefaultValue = ALWAYS
names = ["-o", "--overwrite"], description = ["Overwrite existing options file"], showDefaultValue = ALWAYS
)
var overwrite: Boolean = false
private var overwrite: Boolean = false

@CommandLine.Option(
names = ["-u", "--update"],
description = ["Update existing options by adding missing and removing non-existent options"],
showDefaultValue = ALWAYS
)
var update: Boolean = false
private var update: Boolean = false

override fun run() = if (!path.exists() || overwrite)
with(PatchBundleLoader.Jar(*patchBundles)) {
if (update) setOptions(path)
override fun run() = if (!path.exists() || overwrite) with(PatchBundleLoader.Jar(*patchBundles)) {
if (update) setOptions(path)

Options.serialize(this, prettyPrint = true)
.let(path::writeText)
}
Options.serialize(this, prettyPrint = true).let(path::writeText)
}
else logger.severe("Options file already exists, use --override to override it")
}
Loading

0 comments on commit 0350b7f

Please sign in to comment.