34 lines
1.2 KiB
Kotlin
34 lines
1.2 KiB
Kotlin
package starter
|
|
|
|
import com.electronwill.nightconfig.core.file.FileConfig
|
|
import com.electronwill.nightconfig.core.Config as NightConfig
|
|
|
|
data class StarterConfig(val dependencies: List<Dependency>, val inputs: List<Input>)
|
|
|
|
class Config {
|
|
fun load(): StarterConfig {
|
|
val cfg = FileConfig.of("config.toml")
|
|
cfg.load()
|
|
val dependenciesNode: NightConfig = cfg["dependencies"]
|
|
@Suppress("UNCHECKED_CAST") val dependenciesMap = dependenciesNode.valueMap() as Map<String, NightConfig>
|
|
val dependencies = dependenciesMap.map { (name, values) ->
|
|
Dependency(
|
|
name,
|
|
values["groupId"],
|
|
values["artifactId"],
|
|
values["version"],
|
|
values.getOrElse("default", false),
|
|
values.getEnumOrElse("category", Category.Other)
|
|
)
|
|
}
|
|
|
|
val inputsNode: NightConfig = cfg["inputs"]
|
|
@Suppress("UNCHECKED_CAST") val inputMap = inputsNode.valueMap() as Map<String, NightConfig>
|
|
val inputs = inputMap.map { (name, values) ->
|
|
Input(name, values["display"], values["default"])
|
|
}
|
|
|
|
return StarterConfig(dependencies, inputs)
|
|
}
|
|
|
|
} |