mirror of
https://github.com/Anvilcraft/modpacktools
synced 2024-11-17 23:41:55 +01:00
added shell
config will now always be reloaded to prevent a shell restart being required when config gets generated modpackjson will also be reloaded
This commit is contained in:
parent
6571ba6531
commit
4cfc122dea
4 changed files with 43 additions and 11 deletions
|
@ -43,6 +43,16 @@ private val helpMessage by lazy {
|
|||
|
||||
|
||||
fun main(args: Array<out String>) {
|
||||
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<out String>) {
|
||||
if(args.isEmpty()) {
|
||||
println(helpMessage)
|
||||
} else {
|
||||
|
@ -59,10 +69,4 @@ fun main(args: Array<out String>) {
|
|||
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()
|
||||
}
|
||||
}
|
||||
|
|
28
src/main/kotlin/ley/anvil/modpacktools/commands/Shell.kt
Normal file
28
src/main/kotlin/ley/anvil/modpacktools/commands/Shell.kt
Normal file
|
@ -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<out String>): 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()
|
||||
}
|
||||
}
|
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in a new issue