Add cli command arguments

This commit is contained in:
DBotThePony 2024-05-16 19:32:08 +07:00
parent 67ac2b272e
commit 19324c6247
Signed by: DBot
GPG Key ID: DCC23B5715498507
3 changed files with 62 additions and 14 deletions

View File

@ -23,6 +23,7 @@ val log4jVersion: String by project
val guavaVersion: String by project
val junitVersion: String by project
val sqliteVersion: String by project
val picocliVersion: String by project
repositories {
maven {
@ -91,6 +92,8 @@ dependencies {
implementation("com.github.ben-manes.caffeine:caffeine:$caffeineVersion")
implementation(project(":luna"))
implementation("info.picocli:picocli:$picocliVersion")
implementation("org.xerial:sqlite-jdbc:$sqliteVersion")
implementation("io.netty:netty-transport:$nettyVersion")

View File

@ -17,3 +17,5 @@ log4jVersion=2.17.1
guavaVersion=33.0.0-jre
junitVersion=5.8.2
sqliteVersion=3.45.3.0
picocliVersion=4.7.6

View File

@ -2,30 +2,73 @@ package ru.dbotthepony.kstarbound
import org.apache.logging.log4j.LogManager
import org.lwjgl.Version
import picocli.CommandLine
import picocli.CommandLine.Command
import picocli.CommandLine.Option
import picocli.CommandLine.Parameters
import ru.dbotthepony.kstarbound.client.StarboundClient
import ru.dbotthepony.kstarbound.server.IntegratedStarboundServer
import java.io.File
import java.net.InetSocketAddress
import java.util.concurrent.Callable
import kotlin.system.exitProcess
private val LOGGER = LogManager.getLogger()
fun main() {
Starbound.addArchive(File("J:\\Steam\\steamapps\\common\\Starbound\\assets\\packed.pak"))
@Command(
name = "client",
mixinStandardHelpOptions = true,
description = ["Launches game client"]
)
class StartClientCommand : Callable<Int> {
@Option(names = ["-d", "--data"], description = ["Game folder where Starbound is installed.", "Defaults to working directory."])
var dataFolder: String = "./"
/*for (f in File("J:\\Steam\\steamapps\\workshop\\content\\211820").listFiles()!!) {
for (f2 in f.listFiles()!!) {
if (f2.isFile) {
Starbound.addArchive(f2)
}
@Option(names = ["-s", "--storage"], description = ["Location where to store game files.", "Defaults to game's 'storage' subfolder"])
var storageFolder: String? = null
override fun call(): Int {
val data = File(dataFolder)
if (!data.exists()) {
LOGGER.fatal("No such file ${data.absolutePath}")
return 1
}
}*/
LOGGER.info("Running LWJGL ${Version.getVersion()}")
val file = File("${dataFolder}/assets/packed.pak")
val client = StarboundClient()
if (!file.exists()) {
LOGGER.fatal("No such file ${file.absolutePath}")
return 1
}
Starbound.initializeGame().thenApply {
val server = IntegratedStarboundServer(client, File("./storage"))
server.channels.createChannel(InetSocketAddress(21060))
}.exceptionally { LOGGER.error("what", it); null }
Starbound.addArchive(file)
/*for (f in File("J:\\Steam\\steamapps\\workshop\\content\\211820").listFiles()!!) {
for (f2 in f.listFiles()!!) {
if (f2.isFile) {
Starbound.addArchive(f2)
}
}
}*/
LOGGER.info("Running LWJGL ${Version.getVersion()}")
val client = StarboundClient()
Starbound.initializeGame().thenApply {
val server = IntegratedStarboundServer(client, if (storageFolder == null) File(data, "storage") else File(storageFolder!!))
server.channels.createChannel(InetSocketAddress(21060))
}.exceptionally { LOGGER.error("what", it); null }
return 0
}
}
fun main(vararg args: String) {
val result = CommandLine(StartClientCommand()).execute(*args)
if (result != 0) {
exitProcess(result)
}
}