Skip to content

Commit

Permalink
feat: Make `--out´ option optional
Browse files Browse the repository at this point in the history
  • Loading branch information
oSumAtrIX committed Nov 26, 2023
1 parent 5e63e0a commit 3765957
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 16 deletions.
2 changes: 0 additions & 2 deletions docs/1_usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ ReVanced CLI is divided into the following fundamental commands:
```bash
java -jar revanced-cli.jar patch \
--patch-bundle revanced-patches.jar \
--out patched-app.apk \
--device-serial <device-serial> \
input.apk
```
Expand Down Expand Up @@ -107,7 +106,6 @@ ReVanced CLI is divided into the following fundamental commands:
--include "Some patch" \
--ii 123 \
--exclude "Some other patch" \
--out patched-app.apk \
--device-serial <device-serial> \
--mount \
app.apk
Expand Down
4 changes: 3 additions & 1 deletion src/main/kotlin/app/revanced/cli/command/MainCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ private object CLIVersionProvider : IVersionProvider {
MainCommand::class.java.getResourceAsStream(
"/app/revanced/cli/version.properties"
)?.use { stream ->
Properties().apply { load(stream) }.let {
Properties().apply {
load(stream)
}.let {
"ReVanced CLI v${it.getProperty("version")}"
}
} ?: "ReVanced CLI")
Expand Down
43 changes: 30 additions & 13 deletions src/main/kotlin/app/revanced/cli/command/PatchCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,8 @@ internal object PatchCommand : Runnable {
@CommandLine.Option(
names = ["--options"],
description = ["Path to patch options JSON file."],
showDefaultValue = ALWAYS
)
private var optionsFile: File = File("options.json")
private var optionsFile: File? = null

@CommandLine.Option(
names = ["--exclusive"],
Expand All @@ -80,17 +79,19 @@ internal object PatchCommand : Runnable {
)
private var force: Boolean = false

private var outputFilePath: File? = null

@CommandLine.Option(
names = ["-o", "--out"],
description = ["Path to save the patched APK file to."],
required = true
description = ["Path to save the patched APK file to. Defaults to the same directory as the supplied APK file."],
)
private lateinit var outputFilePath: File
private fun setOutputFilePath(outputFilePath: File?) {
this.outputFilePath = outputFilePath?.absoluteFile
}

@CommandLine.Option(
names = ["-d", "--device-serial"],
description = ["ADB device serial to install to."],
showDefaultValue = ALWAYS
)
private var deviceSerial: String? = null

Expand All @@ -103,14 +104,15 @@ internal object PatchCommand : Runnable {

@CommandLine.Option(
names = ["--keystore"],
description = ["Path to the keystore to sign the patched APK file with."],
description = ["Path to the keystore to sign the patched APK file with. " +
"Defaults to the same directory as the supplied APK file."],
)
private var keystoreFilePath: File? = null

// key store password
@CommandLine.Option(
names = ["--keystore-password"],
description = ["The password of the keystore to sign the patched APK file with."],
description = ["The password of the keystore to sign the patched APK file with. Empty password by default."]
)
private var keyStorePassword: String? = null // Empty password by default

Expand All @@ -137,9 +139,8 @@ internal object PatchCommand : Runnable {
@CommandLine.Option(
names = ["-r", "--resource-cache"],
description = ["Path to temporary resource cache directory."],
showDefaultValue = ALWAYS
)
private var resourceCachePath = File("revanced-resource-cache.")
private var resourceCachePath: File? = null

private var aaptBinaryPath: File? = null

Expand Down Expand Up @@ -209,8 +210,27 @@ internal object PatchCommand : Runnable {
}

override fun run() {
// region Setup

val outputFilePath = outputFilePath ?: File("").absoluteFile.resolve(
"${apk.nameWithoutExtension}-patched.${apk.extension}"
)

val resourceCachePath = resourceCachePath ?: outputFilePath.parentFile.resolve(
"${outputFilePath.nameWithoutExtension}-resource-cache"
)

val optionsFile = optionsFile ?: outputFilePath.parentFile.resolve(
"${outputFilePath.nameWithoutExtension}-options.json"
)

val keystoreFilePath = keystoreFilePath ?: outputFilePath.parentFile
.resolve("${outputFilePath.nameWithoutExtension}.keystore")

val adbManager = deviceSerial?.let { serial -> AdbManager.getAdbManager(serial, mount) }

// endregion

// region Load patches

logger.info("Loading patches")
Expand Down Expand Up @@ -272,9 +292,6 @@ internal object PatchCommand : Runnable {
ApkUtils.copyAligned(apk, this, patcherResult)
}

val keystoreFilePath = keystoreFilePath ?: outputFilePath.absoluteFile.parentFile
.resolve("${outputFilePath.nameWithoutExtension}.keystore")

if (!mount) ApkUtils.sign(
alignedFile,
outputFilePath,
Expand Down

0 comments on commit 3765957

Please sign in to comment.