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 ```bash
java -jar revanced-cli.jar patch \ java -jar revanced-cli.jar patch \
--patch-bundle revanced-patches.jar \ --patch-bundle revanced-patches.jar \
--out patched-app.apk \
--device-serial <device-serial> \ --device-serial <device-serial> \
input.apk input.apk
``` ```
@ -107,7 +106,6 @@ ReVanced CLI is divided into the following fundamental commands:
--include "Some patch" \ --include "Some patch" \
--ii 123 \ --ii 123 \
--exclude "Some other patch" \ --exclude "Some other patch" \
--out patched-app.apk \
--device-serial <device-serial> \ --device-serial <device-serial> \
--mount \ --mount \
app.apk app.apk

View File

@ -18,7 +18,9 @@ private object CLIVersionProvider : IVersionProvider {
MainCommand::class.java.getResourceAsStream( MainCommand::class.java.getResourceAsStream(
"/app/revanced/cli/version.properties" "/app/revanced/cli/version.properties"
)?.use { stream -> )?.use { stream ->
Properties().apply { load(stream) }.let { Properties().apply {
load(stream)
}.let {
"ReVanced CLI v${it.getProperty("version")}" "ReVanced CLI v${it.getProperty("version")}"
} }
} ?: "ReVanced CLI") } ?: "ReVanced CLI")

View File

@ -62,9 +62,8 @@ internal object PatchCommand : Runnable {
@CommandLine.Option( @CommandLine.Option(
names = ["--options"], names = ["--options"],
description = ["Path to patch options JSON file."], description = ["Path to patch options JSON file."],
showDefaultValue = ALWAYS
) )
private var optionsFile: File = File("options.json") private var optionsFile: File? = null
@CommandLine.Option( @CommandLine.Option(
names = ["--exclusive"], names = ["--exclusive"],
@ -80,17 +79,19 @@ internal object PatchCommand : Runnable {
) )
private var force: Boolean = false private var force: Boolean = false
private var outputFilePath: File? = null
@CommandLine.Option( @CommandLine.Option(
names = ["-o", "--out"], names = ["-o", "--out"],
description = ["Path to save the patched APK file to."], description = ["Path to save the patched APK file to. Defaults to the same directory as the supplied APK file."],
required = true
) )
private lateinit var outputFilePath: File private fun setOutputFilePath(outputFilePath: File?) {
this.outputFilePath = outputFilePath?.absoluteFile
}
@CommandLine.Option( @CommandLine.Option(
names = ["-d", "--device-serial"], names = ["-d", "--device-serial"],
description = ["ADB device serial to install to."], description = ["ADB device serial to install to."],
showDefaultValue = ALWAYS
) )
private var deviceSerial: String? = null private var deviceSerial: String? = null
@ -103,14 +104,15 @@ internal object PatchCommand : Runnable {
@CommandLine.Option( @CommandLine.Option(
names = ["--keystore"], 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 private var keystoreFilePath: File? = null
// key store password // key store password
@CommandLine.Option( @CommandLine.Option(
names = ["--keystore-password"], 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 private var keyStorePassword: String? = null // Empty password by default
@ -137,9 +139,8 @@ internal object PatchCommand : Runnable {
@CommandLine.Option( @CommandLine.Option(
names = ["-r", "--resource-cache"], names = ["-r", "--resource-cache"],
description = ["Path to temporary resource cache directory."], 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 private var aaptBinaryPath: File? = null
@ -209,8 +210,27 @@ internal object PatchCommand : Runnable {
} }
override fun run() { 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) } val adbManager = deviceSerial?.let { serial -> AdbManager.getAdbManager(serial, mount) }
// endregion
// region Load patches // region Load patches
logger.info("Loading patches") logger.info("Loading patches")
@ -272,9 +292,6 @@ internal object PatchCommand : Runnable {
ApkUtils.copyAligned(apk, this, patcherResult) ApkUtils.copyAligned(apk, this, patcherResult)
} }
val keystoreFilePath = keystoreFilePath ?: outputFilePath.absoluteFile.parentFile
.resolve("${outputFilePath.nameWithoutExtension}.keystore")
if (!mount) ApkUtils.sign( if (!mount) ApkUtils.sign(
alignedFile, alignedFile,
outputFilePath, outputFilePath,