diff --git a/src/main/kotlin/ley/anvil/modpacktools/Main.kt b/src/main/kotlin/ley/anvil/modpacktools/Main.kt index f951013..cbe6942 100644 --- a/src/main/kotlin/ley/anvil/modpacktools/Main.kt +++ b/src/main/kotlin/ley/anvil/modpacktools/Main.kt @@ -43,6 +43,16 @@ private val helpMessage by lazy { fun main(args: Array) { + runCommand(args) + + //Only close if initialized to prevent creation directly before closing + if(httpClient0.isInitialized()) { + HTTP_CLIENT.dispatcher.executorService.shutdown() + HTTP_CLIENT.connectionPool.evictAll() + } +} + +fun runCommand(args: Array) { if(args.isEmpty()) { println(helpMessage) } else { @@ -59,10 +69,4 @@ fun main(args: Array) { println("Modpackjson is needed for this command yet it is not present.") } } - - //Only close if initialized to prevent creation directly before closing - if(httpClient0.isInitialized()) { - HTTP_CLIENT.dispatcher.executorService.shutdown() - HTTP_CLIENT.connectionPool.evictAll() - } } diff --git a/src/main/kotlin/ley/anvil/modpacktools/commands/Shell.kt b/src/main/kotlin/ley/anvil/modpacktools/commands/Shell.kt new file mode 100644 index 0000000..b6bddcb --- /dev/null +++ b/src/main/kotlin/ley/anvil/modpacktools/commands/Shell.kt @@ -0,0 +1,28 @@ +package ley.anvil.modpacktools.commands + +import ley.anvil.modpacktools.command.CommandReturn +import ley.anvil.modpacktools.command.CommandReturn.Companion.success +import ley.anvil.modpacktools.command.ICommand +import ley.anvil.modpacktools.command.LoadCommand +import ley.anvil.modpacktools.runCommand + +@LoadCommand +object Shell : ICommand { + override val name: String = "shell" + override val helpMessage: String = "opens a shell where mpt commands can be entered in a loop." + + override val needsConfig: Boolean = false + override val needsModpackjson: Boolean = false + + override fun execute(args: Array): CommandReturn { + println("enter \'exit\' to exit the shell\n") + + while(true) { + val arg = readLine()!!.split(' ') + if(arg.getOrNull(0) == "exit") + break + runCommand(arg.toTypedArray()) + } + return success() + } +} \ No newline at end of file diff --git a/src/main/kotlin/ley/anvil/modpacktools/util/Config.kt b/src/main/kotlin/ley/anvil/modpacktools/util/Config.kt index 72f6b7a..0689f07 100644 --- a/src/main/kotlin/ley/anvil/modpacktools/util/Config.kt +++ b/src/main/kotlin/ley/anvil/modpacktools/util/Config.kt @@ -4,8 +4,8 @@ import org.apache.commons.io.FileUtils import java.io.File class Config(val configName: String) { - val configLocation by lazy {File(configName)} - val config by lazy {readConfig()} + val configLocation = File(configName) + val config = readConfig() /** * reads the config it it exists and the default config otherwise @@ -25,7 +25,7 @@ class Config(val configName: String) { * * @return true if the config file exists */ - val exists: Boolean = configLocation.exists() + val exists: Boolean get() = configLocation.exists() /** * Copies the Config file from the resources into the tool's folder diff --git a/src/main/kotlin/ley/anvil/modpacktools/util/ModpackJsonHandler.kt b/src/main/kotlin/ley/anvil/modpacktools/util/ModpackJsonHandler.kt index 21143a0..7ba5bcd 100644 --- a/src/main/kotlin/ley/anvil/modpacktools/util/ModpackJsonHandler.kt +++ b/src/main/kotlin/ley/anvil/modpacktools/util/ModpackJsonHandler.kt @@ -7,8 +7,8 @@ import java.io.FileReader class ModpackJsonHandler(val modpackJsonFile: File) { //Null if no file exists - val asWrapper: ASWrapper? by lazy { - if(modpackJsonFile.exists()) { + val asWrapper: ASWrapper? get() { + return if(modpackJsonFile.exists()) { val reader = FileReader(modpackJsonFile) val ret = ASWrapper(AddonscriptJSON.read(reader, AddonscriptJSON::class.java)) reader.close()