Skip to content

io.github.com6235.configurator 1.0.1

Install 1/2: Add this to pom.xml:
Learn more about Maven or Gradle
<dependency>
  <groupId>io.github.com6235</groupId>
  <artifactId>configurator</artifactId>
  <version>1.0.1</version>
</dependency>
Install 2/2: Run via command line
$ mvn install

About this package

Configirator

Thing to automatically load config from different formats. Supports custom formats.
Uses kotlinx.serialization.

Currently, it supports JSON (json), HOCON (conf, hocon), TOML (toml), YAML (yaml) and Properties (properties)

Latest version: https://github.com/Com6235/maven-libs/packages/2156249

Using as a dependency

Maven

After you added the repository, you can start using my package by adding this to your pom.xml

<dependency>
    <groupId>io.github.com6235</groupId>
    <artifactId>configurator</artifactId>
    <version>${your desired version}</version>
</dependency>

Gradle

After you added the repository, you can start using my package by adding this to dependencies:

In build.gradle.kts:

dependencies {
    implementation("io.github.com6235:configurator:${your desired version}")
}

In build.gradle:

dependencies {
    implementation 'io.github.com6235:configurator:${your desired version}'
}

Examples

Print some info from resources

import io.github.com6235.configurator.ConfigLoader
import kotlinx.serialization.Serializable

@Serializable
data class Config(val helpPages: List<String>)

fun main() {
    val configStream = this::class.java.getResourceAsStream("config.json")!! // change to any format, that it supports
    val config = ConfigLoader(Config.serializer()).loadConfig(configStream, "json") // change to any format, that it supports
    
    println(config.helpPages)
}

Read from input and add to a JSON

import io.github.com6235.configurator.ConfigLoader
import kotlinx.serialization.Serializable

@Serializable
data class Config(val name: String)

fun main() {
    val loader = ConfigLoader(Config.serializer())
    while (true) {
        val s = readln()
        loader.saveConfig(Config(s), Path("./name.json"))
    }
}