feat: Make `--out´ option optional

This commit is contained in:
oSumAtrIX 2023-11-26 04:44:00 +01:00
parent 5e63e0a276
commit 3765957043
No known key found for this signature in database
GPG Key ID: A9B3094ACDB604B4
3 changed files with 33 additions and 16 deletions

View File

@ -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
```
@ -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

View File

@ -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")

View File

@ -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"],
@ -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
@ -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
@ -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
@ -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")
@ -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,