Skip to content

Commit 3cd6dbe

Browse files
committed
feat: Set patch options via CLI
1 parent 5a1642c commit 3cd6dbe

File tree

7 files changed

+243
-135
lines changed

7 files changed

+243
-135
lines changed

docs/1_usage.md

+72-10
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ java -jar revanced-cli.jar -h
1313
## 📃 List patches
1414

1515
```bash
16-
java -jar revanced-cli.jar list-patches --with-descriptions --with-packages --with-versions --with-options --with-universal-patches revanced-patches.rvp
16+
java -jar revanced-cli.jar list-patches --with-packages --with-versions --with-options revanced-patches.rvp
1717
```
1818

19-
## 💉 Patch an app with the default list of patches
19+
## 💉 Patch an app
20+
21+
To patch an app using the default list of patches, use the `patch` command:
2022

2123
```bash
2224
java -jar revanced-cli.jar patch -b revanced-patches.rvp input.apk
@@ -28,22 +30,37 @@ You can also use multiple patch bundles:
2830
java -jar revanced-cli.jar patch -b revanced-patches.rvp -b another-patches.rvp input.apk
2931
```
3032

31-
To manually include or exclude patches, use the options `-i` and `-e`.
32-
Keep in mind the name of the patch must be an exact match.
33-
You can also use the options `--ii` and `--ie` to include or exclude patches by their index
34-
if two patches have the same name.
35-
To know the indices of patches, use the option `--with-indices` when listing patches:
33+
To change the default set of used patches, use the option `-i` or `-e` to use or disuse specific patches.
34+
You can use the `list-patches` command to see which patches are used by default.
35+
36+
To only use specific patches, you can use the option `--exclusive` combined with `-i`.
37+
Remember that the options `-i` and `-e` match the patch's name exactly. Here is an example:
3638

3739
```bash
38-
java -jar revanced-cli.jar list-patches --with-indices revanced-patches.rvp
40+
java -jar revanced-cli.jar patch -b revanced-patches.rvp --exclusive -i "Patch name" -i "Another patch name" input.apk
3941
```
4042

41-
Then you can use the indices to include or exclude patches:
43+
You can also use the options `--ii` and `--ie` to use or disuse patches by their index.
44+
This is useful, if two patches happen to have the same name.
45+
To know the indices of patches, use the command `list-patches`:
46+
47+
```bash
48+
java -jar revanced-cli.jar list-patches revanced-patches.rvp
49+
```
50+
51+
Then you can use the indices to use or disuse patches:
4252

4353
```bash
4454
java -jar revanced-cli.jar patch -b revanced-patches.rvp --ii 123 --ie 456 input.apk
4555
```
4656

57+
You can combine the option `-i`, `-e`, `--ii`, `--ie` and `--exclusive`. Here is an example:
58+
59+
```bash
60+
java -jar revanced-cli.jar patch -b revanced-patches.rvp --exclusive -i "Patch name" --ii 123 input.apk
61+
```
62+
63+
4764
> [!TIP]
4865
> You can use the option `-d` to automatically install the patched app after patching.
4966
> Make sure ADB is working:
@@ -62,7 +79,52 @@ java -jar revanced-cli.jar patch -b revanced-patches.rvp --ii 123 --ie 456 input
6279
> adb install input.apk
6380
> ```
6481
65-
## 📦 Install an app manually
82+
Patches can have options you can set using the option `--set-options`.
83+
To know the options of a patch, use the option `--with-options` when listing patches:
84+
85+
```bash
86+
java -jar revanced-cli.jar list-patches --with-options revanced-patches.rvp
87+
```
88+
89+
Each patch can have multiple options. You can set them using the option `--set-options`.
90+
For example, to set the options for the patch with the name `Patch name`
91+
with the key `key1` and `key2` to `value1` and `value2` respectively, use the following command:
92+
93+
```bash
94+
java -jar revanced-cli.jar patch -b revanced-patches.rvp --set-options "Patch name" -Okey1=value1 -Okey2=value2 input.apk
95+
```
96+
97+
If you want to set a value to `null`, you can omit the value:
98+
99+
```bash
100+
java -jar revanced-cli.jar patch -b revanced-patches.rvp --set-options "Patch name" -Okey1 input.apk
101+
```
102+
103+
> [!WARNING]
104+
> The values of options are typed. If you set a value with the wrong type, the patching process will fail.
105+
> The type of the option value can be seen when listing patches with the option `--with-options`.
106+
>
107+
> Example values:
108+
>
109+
> String: `string`
110+
> Boolean: `true`, `false`
111+
> Integer: `123`
112+
> Double: `1.0`
113+
> Float: `1.0f`
114+
> Long: `1234567890`, `1L`
115+
> List: `item1,item2,item3`
116+
>
117+
> In addition to that, you can escape quotes (`\"`, `\'`) and commas (`\,`) to treat values as string literals:
118+
>
119+
> Integer as string: `\'123\'`
120+
> List with an integer, an integer as a string and a string with a comma: `123,\'123\',str\,ing`
121+
>
122+
> Example command with escaped quotes:
123+
>
124+
> ```bash
125+
> java -jar revanced-cli.jar -b revanced-patches.rvp --set-options "Patch name" -OstringKey=\'1\' input.apk
126+
> ```
127+
## 📦 Install an app manually
66128
67129
```bash
68130
java -jar revanced-cli.jar utility install -a input.apk

src/main/kotlin/app/revanced/cli/command/ListCompatibleVersions.kt

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package app.revanced.cli.command
22

33
import app.revanced.library.PackageName
4-
import app.revanced.library.PatchUtils
54
import app.revanced.library.VersionMap
5+
import app.revanced.library.mostCommonCompatibleVersions
66
import app.revanced.patcher.patch.loadPatchesFromJar
77
import picocli.CommandLine
88
import java.io.File
@@ -12,7 +12,7 @@ import java.util.logging.Logger
1212
name = "list-versions",
1313
description = [
1414
"List the most common compatible versions of apps that are compatible " +
15-
"with the patches in the supplied patch bundles.",
15+
"with the patches in the supplied patch bundles.",
1616
],
1717
)
1818
internal class ListCompatibleVersions : Runnable {
@@ -58,8 +58,7 @@ internal class ListCompatibleVersions : Runnable {
5858

5959
val patches = loadPatchesFromJar(patchBundles)
6060

61-
PatchUtils.getMostCommonCompatibleVersions(
62-
patches,
61+
patches.mostCommonCompatibleVersions(
6362
packageNames,
6463
countUnusedPatches,
6564
).entries.joinToString("\n", transform = ::buildString).let(logger::info)

src/main/kotlin/app/revanced/cli/command/ListPatchesCommand.kt

+3-1
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,11 @@ internal object ListPatchesCommand : Runnable {
9595
} ?: append("Key: $key")
9696

9797
values?.let { values ->
98-
appendLine("\nValid values:")
98+
appendLine("\nPossible values:")
9999
append(values.map { "${it.value} (${it.key})" }.joinToString("\n").prependIndent("\t"))
100100
}
101+
102+
append("\nType: $type")
101103
}
102104

103105
fun IndexedValue<Patch<*>>.buildString() =

src/main/kotlin/app/revanced/cli/command/MainCommand.kt

-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ private object CLIVersionProvider : IVersionProvider {
3434
versionProvider = CLIVersionProvider::class,
3535
subcommands = [
3636
PatchCommand::class,
37-
OptionsCommand::class,
3837
ListPatchesCommand::class,
3938
ListCompatibleVersions::class,
4039
UtilityCommand::class,
Original file line numberDiff line numberDiff line change
@@ -1,62 +0,0 @@
1-
package app.revanced.cli.command
2-
3-
import app.revanced.library.Options
4-
import app.revanced.library.Options.setOptions
5-
import app.revanced.patcher.patch.loadPatchesFromJar
6-
import picocli.CommandLine
7-
import picocli.CommandLine.Help.Visibility.ALWAYS
8-
import java.io.File
9-
import java.util.logging.Logger
10-
11-
@CommandLine.Command(
12-
name = "options",
13-
description = ["Generate options file from patches."],
14-
)
15-
internal object OptionsCommand : Runnable {
16-
private val logger = Logger.getLogger(OptionsCommand::class.java.name)
17-
18-
@CommandLine.Parameters(
19-
description = ["Paths to patch bundles."],
20-
arity = "1..*",
21-
)
22-
private lateinit var patchBundles: Set<File>
23-
24-
@CommandLine.Option(
25-
names = ["-p", "--path"],
26-
description = ["Path to patch options JSON file."],
27-
showDefaultValue = ALWAYS,
28-
)
29-
private var filePath: File = File("options.json")
30-
31-
@CommandLine.Option(
32-
names = ["-o", "--overwrite"],
33-
description = ["Overwrite existing options file."],
34-
showDefaultValue = ALWAYS,
35-
)
36-
private var overwrite: Boolean = false
37-
38-
@CommandLine.Option(
39-
names = ["-u", "--update"],
40-
description = ["Update existing options by adding missing and removing non-existent options."],
41-
showDefaultValue = ALWAYS,
42-
)
43-
private var update: Boolean = false
44-
45-
override fun run() =
46-
try {
47-
loadPatchesFromJar(patchBundles).let { patches ->
48-
val exists = filePath.exists()
49-
if (!exists || overwrite) {
50-
if (exists && update) patches.setOptions(filePath)
51-
52-
Options.serialize(patches, prettyPrint = true).let(filePath::writeText)
53-
} else {
54-
throw OptionsFileAlreadyExistsException()
55-
}
56-
}
57-
} catch (ex: OptionsFileAlreadyExistsException) {
58-
logger.severe("Options file already exists, use --overwrite to override it")
59-
}
60-
61-
class OptionsFileAlreadyExistsException : Exception()
62-
}

0 commit comments

Comments
 (0)