From 3765957043989fe7a8932a0c548566a78d04fc41 Mon Sep 17 00:00:00 2001 From: oSumAtrIX Date: Sun, 26 Nov 2023 04:44:00 +0100 Subject: [PATCH] =?UTF-8?q?feat:=20Make=20`--out=C2=B4=20option=20optional?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/1_usage.md | 2 - .../app/revanced/cli/command/MainCommand.kt | 4 +- .../app/revanced/cli/command/PatchCommand.kt | 43 +++++++++++++------ 3 files changed, 33 insertions(+), 16 deletions(-) diff --git a/docs/1_usage.md b/docs/1_usage.md index 1a885b42..3b7ca4ab 100644 --- a/docs/1_usage.md +++ b/docs/1_usage.md @@ -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 \ 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 \ --mount \ app.apk diff --git a/src/main/kotlin/app/revanced/cli/command/MainCommand.kt b/src/main/kotlin/app/revanced/cli/command/MainCommand.kt index d088e1e2..49de7016 100644 --- a/src/main/kotlin/app/revanced/cli/command/MainCommand.kt +++ b/src/main/kotlin/app/revanced/cli/command/MainCommand.kt @@ -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") diff --git a/src/main/kotlin/app/revanced/cli/command/PatchCommand.kt b/src/main/kotlin/app/revanced/cli/command/PatchCommand.kt index 2d25c9d8..a970c2f3 100644 --- a/src/main/kotlin/app/revanced/cli/command/PatchCommand.kt +++ b/src/main/kotlin/app/revanced/cli/command/PatchCommand.kt @@ -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,