diff --git a/src/main/kotlin/app/revanced/cli/command/utility/InstallCommand.kt b/src/main/kotlin/app/revanced/cli/command/utility/InstallCommand.kt index 7ecddeed..dd825936 100644 --- a/src/main/kotlin/app/revanced/cli/command/utility/InstallCommand.kt +++ b/src/main/kotlin/app/revanced/cli/command/utility/InstallCommand.kt @@ -7,6 +7,7 @@ import kotlinx.coroutines.runBlocking import picocli.CommandLine.* import java.io.File import java.util.logging.Logger +import kotlin.system.exitProcess @Command( name = "install", @@ -44,20 +45,35 @@ internal object InstallCommand : Runnable { }.install(Installer.Apk(apk, packageName)) } catch (e: Exception) { logger.severe(e.toString()) + throw e } when (result) { - RootInstallerResult.FAILURE -> + RootInstallerResult.SUCCESS -> + logger.info("Mounted the APK file") + RootInstallerResult.FAILURE -> { logger.severe("Failed to mount the APK file") - is AdbInstallerResult.Failure -> - logger.severe(result.exception.toString()) - else -> + throw Exception() + } + AdbInstallerResult.Success -> logger.info("Installed the APK file") + is AdbInstallerResult.Failure -> { + logger.severe("Failed to install the APK file: ${result.exception}") + throw Exception() + } + else -> { + logger.severe("Unknown installation result") + throw Exception() + } } } runBlocking { - deviceSerials?.map { async { install(it) } }?.awaitAll() ?: install() + try { + deviceSerials?.map { async { install(it) } }?.awaitAll() ?: install() + } catch (_: Exception) { + exitProcess(1) + } } } } diff --git a/src/main/kotlin/app/revanced/cli/command/utility/UninstallCommand.kt b/src/main/kotlin/app/revanced/cli/command/utility/UninstallCommand.kt index 3477e8ad..3a8e186e 100644 --- a/src/main/kotlin/app/revanced/cli/command/utility/UninstallCommand.kt +++ b/src/main/kotlin/app/revanced/cli/command/utility/UninstallCommand.kt @@ -10,6 +10,7 @@ import kotlinx.coroutines.runBlocking import picocli.CommandLine.* import picocli.CommandLine.Help.Visibility.ALWAYS import java.util.logging.Logger +import kotlin.system.exitProcess @Command( name = "uninstall", @@ -48,19 +49,35 @@ internal object UninstallCommand : Runnable { }.uninstall(packageName) } catch (e: Exception) { logger.severe(e.toString()) + throw e } when (result) { - RootInstallerResult.FAILURE -> + RootInstallerResult.SUCCESS -> + logger.info("Unmounted the patched APK file") + RootInstallerResult.FAILURE -> { logger.severe("Failed to unmount the patched APK file") - is AdbInstallerResult.Failure -> + throw Exception() + } + AdbInstallerResult.Success -> + logger.info("Uninstalled the patched APK file") + is AdbInstallerResult.Failure -> { logger.severe(result.exception.toString()) - else -> logger.info("Uninstalled the patched APK file") + throw Exception() + } + else -> { + logger.severe("Unknown uninstallation result") + throw Exception() + } } } runBlocking { - deviceSerials?.map { async { uninstall(it) } }?.awaitAll() ?: uninstall() + try { + deviceSerials?.map { async { uninstall(it) } }?.awaitAll() ?: uninstall() + } catch (_: Exception) { + exitProcess(1) + } } } }