From dd9dd5b7ec440f8d65d999d77dc9cc8eb78d7826 Mon Sep 17 00:00:00 2001 From: isXander Date: Sun, 7 Nov 2021 19:16:13 +0000 Subject: [PATCH] fix --help cli --- .../kotlin/org/bundleproject/installer/Main.kt | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/main/kotlin/org/bundleproject/installer/Main.kt b/src/main/kotlin/org/bundleproject/installer/Main.kt index a96a6f8..551ab94 100644 --- a/src/main/kotlin/org/bundleproject/installer/Main.kt +++ b/src/main/kotlin/org/bundleproject/installer/Main.kt @@ -4,7 +4,9 @@ import com.google.gson.* import com.xenomachina.argparser.ArgParser import com.xenomachina.argparser.DefaultHelpFormatter import com.xenomachina.argparser.default +import com.xenomachina.argparser.mainBody import io.ktor.client.request.* +import kotlinx.coroutines.runBlocking import org.bundleproject.installer.api.response.VersionResponse import org.bundleproject.installer.gui.frames.InstallerGui import org.bundleproject.installer.updater.getLatestUpdate @@ -21,9 +23,9 @@ import javax.swing.JOptionPane * * @since 0.0.1 */ -suspend fun main(args: Array) { +fun main(args: Array) = mainBody { ArgParser(args, helpFormatter = DefaultHelpFormatter()).parseInto(::InstallerParams).run { - val update = if (!noUpdate) getLatestUpdate().takeIf { it != INSTALLER_VERSION } else null + val update = if (!noUpdate) runBlocking { getLatestUpdate() }.takeIf { it != INSTALLER_VERSION } else null if (silent) { if (update != null) { @@ -34,15 +36,16 @@ suspend fun main(args: Array) { if (path == null) throw IllegalArgumentException("Path does not exist or it wasn't specified.") - if (!multimc) installOfficial(path!!, mcversion, inject) - else installMultiMC(getMultiMCInstanceFolder(path!!)!!, mcversion) + runBlocking { + if (!multimc) installOfficial(path!!, mcversion, inject) + else installMultiMC(getMultiMCInstanceFolder(path!!)!!, mcversion) + } - return + return@mainBody } InstallerGui.isVisible = true - if (update != null) { JOptionPane.showOptionDialog(InstallerGui, "There is an installer update available!", "Installer Update", JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE, null, arrayOf("Update", "Maybe Later"), "Update").also { if (it == JOptionPane.YES_OPTION) { @@ -247,7 +250,7 @@ class InstallerParams(parser: ArgParser) { val inject by parser.flagging( "-i", "--inject", - help = "Inject profile rather than creating a new one. (Only affected in official launcher install)" + help = "Inject profile rather than creating a new one. (Only affected in official launcher install)", ).default { true } val noUpdate by parser.flagging(